开发者

POST method of httplib python gives an error "socket.gaierror: [Errno -2] Name or service not known"

开发者 https://www.devze.com 2023-03-29 00:05 出处:网络
The following code throws an error \"socket.gaierror: [Errno -2] Name or service not known\". import httplib, urllib

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开发者_Python百科")
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.


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)


Try the following code:

conn = httplib.HTTPSConnection("x.x.x.x",port=8181)


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")
0

精彩评论

暂无评论...
验证码 换一张
取 消