httplib python 的 POST 方法给出错误“socket.gaierror: [Errno -2] 名称或服务未知”
以下代码抛出错误“socket.gaierror: [Errno -2] 名称或服务未知”。
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
我不想使用 urllib2 模块。 有人可以帮我吗?... 如何保存该服务器的状态?,以便下次我直接发布 uri 的值。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您没有正确指定非默认端口:
http://docs.python.org/release/2.6 .7/library/httplib.html#httplib.HTTPSConnection
试试这个:
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:
尝试以下代码:
Try the following code:
我在 httplib.HTTPConnection 中遇到了类似的错误,我发现将 url 从“http://xxxx”更改为“xxxx”对我有用。尝试删除“http://”或“https://”。
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://".