[Tutor] webservice question

2015-01-29 Thread Phil H
 Looking for a little help.  I'm working on a little project and think using 
python would be the best way to do it.  I am a novice but have read a few 
beginners books.  Well to not waste everyones time i'll just get to it.  I'm 
looking to use web services to get and post data from a server with a java rest 
interface
 
This is what I have been given from the Java end
Java method
public java.lang.String getSettings (java.lang.String username, 
java.lang.String pass, java.lang.String key, java.lang.string tag)
 
url example http://localhost:8080/gettag/tag(retrieve a tag from a DB)
 
i'm told it should return something like this
   [tag''s value] 
   
 
So for what is working
 

import urllib2
import requests

url = 'http://localhost:8080/gettag/testconnection'
response = urllib2.urlopen(url) .read()

print response
--
 
with this I get the expected response from the server
 
then I have a test to authenticate user and pass
 
url = 'http://localhost:8080/gettag/testauth?username=testuser&pass=123456'
 
and this works
 
This is where I get confused, how do I pass the variable key's value and return 
the variable tag's value.
 
 
Thanks in advance for any help, I've tried a bunch of stuff and its just not 
working.
 
Phil
 
 
 
 
 
 
 
 
 
 

 
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] webservice question

2015-01-29 Thread Alan Gauld

On 29/01/15 05:37, Phil H wrote:


public java.lang.String getSettings (java.lang.String username,

  java.lang.String pass,
  java.lang.String key,
  java.lang.string tag)


i'm told it should return something like this
   [tag''s value]  
 




then I have a test to authenticate user and pass

url = 'http://localhost:8080/gettag/testauth?username=testuser&pass=123456'
and this works

This is where I get confused, how do I pass the variable key's value
and return the variable tag's value.




Thanks in advance for any help, I've tried a bunch of stuff and its just not 
working.


It would probably help if you'd shown us at least one of your attempts 
so we can see where your thinking has been going... also the response back.


But at a guess I'd have thought you used a URL of:

url = 
'http://localhost:8080/gettag/getSettings?username=testuser&pass=123456&key=&tag='


Since that seems to be the API signature?

But I'm no expert on Restful web services so I could well be wrong.
Is that close to what you tried?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] webservice question

2015-01-29 Thread Danny Yoo
On Wed, Jan 28, 2015 at 9:37 PM, Phil H  wrote:
>  Looking for a little help.  I'm working on a little project and think using 
> python would be the best way to do it.  I am a novice but have read a few 
> beginners books.  Well to not waste everyones time i'll just get to it.  I'm 
> looking to use web services to get and post data from a server with a java 
> rest interface


I think the question needs a little clarification here.  You're
mentioning both clients and servers in the same question, so it's a
little unclear what you're aiming for.

Are you writing a client, or a server?  Or both?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: webservice question

2015-01-29 Thread Danny Yoo
Hi Phil,

Let me forward your response to tutor.  My apologies; I'm right in the
middle of work, and can't respond promptly at the moment.  Please use
Reply to All in the future on Tutor so that responses can distribute
across the list, rather than run into hotspots.


-- Forwarded message --
From: Phil H 
Date: Thu, Jan 29, 2015 at 12:55 PM
Subject: Re: [Tutor] webservice question
To: Danny Yoo 


Danny,


I was writing the client in Python to talk to the server in Java.  I
believe I have figured it out, the java doc had typoes in it and once
I got that fixed it is returning the data I expected to see

Sent from my iPhone

> On Jan 29, 2015, at 1:56 PM, "Danny Yoo"  wrote:
>
>> On Wed, Jan 28, 2015 at 9:37 PM, Phil H  wrote:
>> Looking for a little help.  I'm working on a little project and think using 
>> python would be the best way to do it.  I am a novice but have read a few 
>> beginners books.  Well to not waste everyones time i'll just get to it.  I'm 
>> looking to use web services to get and post data from a server with a java 
>> rest interface
>
>
> I think the question needs a little clarification here.  You're
> mentioning both clients and servers in the same question, so it's a
> little unclear what you're aiming for.
>
> Are you writing a client, or a server?  Or both?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Umm.. I need help on changing Global Variables.

2015-01-29 Thread Tallen Grey Smith
So, I’m trying to make a very simple game that involves time management 
properly, but I’m having an issue.

level = 1
player_health = 100
enemy_health = 100
steps = 10
civilians = 20
charge = 0
name_2 = 'Bob'

def game():

global level
global player_health
global enemy_health
global steps
global civilians
global charge



print "\n" * 80
print "Level " + str(level)
print  name_2 +": " + str(player_health) +" HP"
print "Centurion: " + str(enemy_health) + " HP"
print "Distance: " + str(steps) + " feet"
print "Weapon Charge: " + str(charge)
print "Civilians Remaining: " + str(civilians)
print "A Centurion lands near the gate! Prepare the Laser!"
action_1 = raw_input("Do you want to charge the laser or fire?")
action_2 = action_1.lower()

if action_2 == "charge":
charge == charge+10
steps == steps-1
civilians == civilians -1
charge_1()


def charge_1():

level
player_health
enemy_health
steps
civilians
charge
print "\n" * 80
print "Level " + str(level)
print  name_2 +": " + str(player_health) +" HP"
print "Centurion: " + str(enemy_health) + " HP"
print "Distance: " + str(steps) + " feet"
print "Weapon Charge: " + str(charge)
print "Civilians Remaining: " + str(civilians)
print "The Centurion moves closer! Hurry!"
action_1 = raw_input("Do you want to charge the laser or fire?")
action_2 = action_1.lower()

if action_2 == "charge":
charge = charge+10
steps = steps-1
civilians = civilians -1
charge_1()

game()


thats my code, and I want it to where if I type charge it’ll make my charge go 
up 10, my steps go down 1, my divs going down 1, and it to go to my charge_1 
function, which should do the same thing but with a tweaked dialog box. But no 
matter how hard i try, once it gets to the charge_1, it always says that the 
variables that I changed where referenced in previous functions and it can’t 
pull them. How can I change this to get a variable that when changed in my If 
statement, would be useable in other functions?
Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Umm.. I need help on changing Global Variables.

2015-01-29 Thread Alan Gauld

On 29/01/15 17:16, Tallen Grey Smith wrote:


def game():

 global level
 global player_health
 global enemy_health
 global steps
 global civilians
 global charge



This is fine.
But it only tells this function to treat them as globals.


def charge_1():

 level
 player_health
 enemy_health
 steps
 civilians
 charge


This does nothing useful.
You need to tell the function that they are global just as
you did above. Global variables are considered bad practice
so Python doesn't make it easy to use them. (Although a
lot easier than some languages)

There are quite a few other things we could comment on in your
code but this should resolve the immediate issue.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor