how python http request and response works
Posted
by Apache
on Stack Overflow
See other posts from Stack Overflow
or by Apache
Published on 2010-04-12T06:28:39Z
Indexed on
2010/04/12
6:33 UTC
Read the original article
Hit count: 496
hi expert, i'm newbie for python, i use to learn using sample, i use python to scan wifi to get ssid, and now i want to send the data to the server, then i did as follow
import httplib,urllib
params = urllib.urlencode({"ssid":"guest"})
headers = {"Content-type":"application/x-www-form-urlencoded","Accept":"text/plain"}
conn=httplib.HTTPConnection("http://223.56.124.58:8080/wireless")
conn.request("POST","data",params,headers)
response = conn.getresponse()
print "Response"
print response.status
print "-----"
print response.reason
data = response.read()
print data
conn.close()
but when execute the code i'm getting as follow
root@dave-laptop:~# python http.py Traceback (most recent call last): File "http.py", line 9, in conn.request("POST","http://202.45.139.58:8080/ppod-web",params,headers) File "/usr/lib/python2.6/httplib.py", line 898, in request self._send_request(method, url, body, headers) File "/usr/lib/python2.6/httplib.py", line 935, in _send_request self.endheaders() File "/usr/lib/python2.6/httplib.py", line 892, in endheaders self._send_output() File "/usr/lib/python2.6/httplib.py", line 764, in _send_output self.send(msg) File "/usr/lib/python2.6/httplib.py", line 723, in send self.connect() File "/usr/lib/python2.6/httplib.py", line 704, in connect self.timeout) File "/usr/lib/python2.6/socket.py", line 500, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno -2] Name or service not known
can anyone help me
the code should be like this when rum in the url
http://223.56.124.58:8080/wireless?data={"wifi":{"ssid":"guest","rssi","80"}}
how to set like this or other way to do this to send to the server
thanks
© Stack Overflow or respective owner