I’m trying to make http request with python:
class DownloadManager():
def __init__(self, servername):
self.conn = httplib.HTTPConnection(servername)
print self.conn
def download(self, modname):
params = urllib.urlencode({"name" : modname})
self.conn.request("GET", "/getmod", params)
resp = self.conn.getresponse()
print resp.status
print resp.reason
if resp.status == 200:
url = resp.read()
else:
return
mod = urllib2.urlopen(url)
return mod.read()
But getting:
400
Bad request
In server log I see:
WARNING 2011-08-15 06:58:39,692 dev_appserver.py:4013] Request body in GET is not permitted: name=Test
INFO 2011-08-15 06:58:39,692 dev_appserver.py:4248] "GET /getmod HTTP/1.1" 400 -
What’s wrong?
The GET request method can’t have anything in the body. If you want to pass arguments via the GET method, you have to add the url-encoded parameters to the URL after a question mark ‘?’ character:
However, what it appears you really want to do is a POST request: