POST method of httplib python gives an error "socket.gaierror: [Errno -2] Name or service not known"
The following code throws an error "socket.gaierror: [Errno -2] Name or service not known".
import httplib, urllib
attrs = urllib.urlencode({"username":"admin", "password":"admin"})
conn = httplib.HTTPSConnection("https://x.x.x.x:8181")
conn.request("POST", "/login", attrs)
response = conn.getresponse()
print response.status, response.reason
I don't want to use urllib2 module. Could anybody help me?... How to save the state of that server?, so that next time i directly post the values for the uri.
-
can you manually resolve the address?Uku Loskit– Uku Loskit2011年08月19日 08:16:33 +00:00Commented Aug 19, 2011 at 8:16
-
Yes, I can manually resolve the address. The above thing working fine with urllib2 module. But the need to use httplib.ameet– ameet2011年08月19日 08:20:59 +00:00Commented Aug 19, 2011 at 8:20
3 Answers 3
I think you are not specifying the non-default port correctly: http://docs.python.org/release/2.6.7/library/httplib.html#httplib.HTTPSConnection
Try this instead:
conn = httplib.HTTPSConnection("https://x.x.x.x",port=8181)
Comments
Try the following code:
conn = httplib.HTTPSConnection("x.x.x.x",port=8181)
Comments
I was getting a similar error with httplib.HTTPConnection, I found changing the url from "http://x.x.x.x" to "x.x.x.x" worked for me. Try removing the "http://" or "https://".
conn = httplib.HTTPSConnection("x.x.x.x:8181")