httplib python 的 POST 方法给出错误“socket.gaierror: [Errno -2] 名称或服务未知”

发布于 2024-11-30 21:30:49 字数 400 浏览 5 评论 0原文

以下代码抛出错误“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心碎无痕… 2024-12-07 21:30:49

我认为您没有正确指定非默认端口:
http://docs.python.org/release/2.6 .7/library/httplib.html#httplib.HTTPSConnection

试试这个:

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

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)
清泪尽 2024-12-07 21:30:49

尝试以下代码:

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

Try the following code:

conn = httplib.HTTPSConnection("x.x.x.x",port=8181)
‖放下 2024-12-07 21:30:49

我在 httplib.HTTPConnection 中遇到了类似的错误,我发现将 url 从“http://xxxx”更改为“xxxx”对我有用。尝试删除“http://”或“https://”。

conn = httplib.HTTPSConnection("x.x.x.x: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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文