I'm newbie for python, I'm having task so I need to scan wifi and send the data to the server, the below is the format which i have to send, this work fine when enter manually in browser url text box,
http://223.56.124.58:8080/ppod-web/ProcessRawData?data={"userId":"2220081127-14","timestamp":"2010-04-12 10:54:24","wifi":{"ssid":"guest","rssi":"80"}}
here is my code:
import httplib
import urllib
params = urllib.urlencode('{\"userId\":\"20081127-14\",\"timestamp\":\"2010-04-12 10:54:24\",\"wifi\":{\"ssid\":\"guest\",\"rssi\":\"80\"}}')
headers = {"Content-type":"application/x-www-form-urlencoded","Accept":"text/plain"}
conn = httplib.HTTPConnection("http://223.56.124.58:8080")
conn.request("POST","ppod-web/ProcessRawData?data=",params,headers)
response = conn.getresponse()
print response.status
print "-----"
print response.reason
data = response.read()
print data
conn.close()
thanks
The traceback doesn't come from the same code you pasted.
On the error traceback there's a line:
It is the line 9 of
http.py
however it is not on the code you pasted.Please paste the actual code.
Instead of:
try:
Not sure if it will resolve all your problems, but at least your code will conform to the method/constructor signatures.
Most likely, the issue with the script you posted in the question is you cannot directly do:
The exception is triggered in
getaddrinfo()
, which calls the C functiongetaddrinfo()
which returnsEAI_NONAME
:There obviously is a problem with the parameters passed to
getaddrinfo
, and most likely you are trying to get information for the"223.56.124.58:8080/wireless"
host. Ooops!Indeed, you cannot directly connect to an URL address. As the documentation clearly states and shows, you connect to the server:
Then you can do:
What about the script you are actually using?
Even if the connection was correctly formed, that would have you POSTing to
http://202.45.139.58:8080/http://202.45.139.58:8080/ppod-web
. What you really want probably is:The error is shown for this line because most likely
HTTPConnection
is a lazy object and only attempts to actually connect to the server when you callrequest()
.After you're done fixing the above, you'll need to fix
params
.To get what you
think youwant to get, you should do: