Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass one parameter in a Tornado HttpGet with several parameters

I want pass one parameter in a Url (to update one of many paramaters contained by my URL) like this:

httpGet.setURI(new URI(url/user?"nickname"="John") 

ServerSide in Python:

class GetInfo(BaseHandler):
  def Get(self):
        nickname = self.get_argument("nickname")
        gender = self.get_argument("gender")
        logging.info(nickname)
        logging.info(gender)

  application = tornado.web.Application([
  (r"/", MainHandler),
  (r"/user", GetInfo),
  ])

The server told me that I can't do this because the parameter "gender" is missing. How can I do?

Thanks

like image 946
user420574 Avatar asked Jan 15 '11 18:01

user420574


1 Answers

First your URI seems to be wrong.

httpGet.setURI(new URI(url + "/user?nickname=John") 

And if you test from emulator to webserver and you use both on the same machine, use the IP address of the server instead of something like localhost or 127.0.0.1

Example:

String url = "http://192.168.1.104";
httpGet.setURI(new URI(url + "/user?nickname=John");

Edit: The answer to this OP is below:

it seems from the example at tornadoweb.org/documentation that you can set a default value. So you can try something like gender = self.get_argument("gender",None) . So gender should be set to None if you dont pass any gender parameter in the query string

like image 158
ccheneson Avatar answered Sep 16 '22 23:09

ccheneson