/home 出现 gai 错误 [Errno -2] 名称或服务未知
根据 httplib 文档中的示例:
>>> import httplib, urllib
>>> params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
... "Accept": "text/plain"}
>>> conn = httplib.HTTPConnection("bugs.python.org")
>>> conn.request("POST", "", params, headers)
>>> response = conn.getresponse()
>>> print response.status, response.reason
302 Found
>>> data = response.read()
>>> data
'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
>>> conn.close()
我的代码是:
import httplib
import urllib
token = request.POST.get('token')
if token:
params = urllib.urlencode({'apiKey':'[some string]', 'token':token})
connection = httplib.HTTPSConnection('rpxnow.com/api/v2/auth_info')
connection.request('POST', "", params)
response = connection.getresponse()
print response.read()
检查我的本地变量 yeilds:
连接:“httplib.HTTPSConnection 实例位于 0x8baa4ac” params: 'token=[some string]&apiKey=[some string]'
(我进行此调用的说明是:
使用令牌进行 auth_info API 调用: 网址:https://rpxnow.com/api/v2/auth_info 参数:
apiKey [一些字符串] 代币 您在上面提取的令牌值)
但我收到主题行中提到的错误。为什么?
per the example in the httplib docs:
>>> import httplib, urllib
>>> params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
... "Accept": "text/plain"}
>>> conn = httplib.HTTPConnection("bugs.python.org")
>>> conn.request("POST", "", params, headers)
>>> response = conn.getresponse()
>>> print response.status, response.reason
302 Found
>>> data = response.read()
>>> data
'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
>>> conn.close()
my code is:
import httplib
import urllib
token = request.POST.get('token')
if token:
params = urllib.urlencode({'apiKey':'[some string]', 'token':token})
connection = httplib.HTTPSConnection('rpxnow.com/api/v2/auth_info')
connection.request('POST', "", params)
response = connection.getresponse()
print response.read()
inspection of my local vars yeilds:
connection: "httplib.HTTPSConnection instance at 0x8baa4ac"
params: 'token=[some string]&apiKey=[some string]'
(My instructions to make this call are:
Use the token to make the auth_info API call:
URL: https://rpxnow.com/api/v2/auth_info
Parameters:
apiKey
[some string]
token
The token value you extracted above)
but I'm getting the error mentioned in the subject line. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道 rpxnow.com 是什么,也不熟悉他们的 API,但此错误消息表明他们没有响应该 URL 上的请求的服务(即“rpxnow.com/api/v2/auth_info”) )。
您能否验证他们的服务是否已在该 URL 上启动并运行?
I don't know what rpxnow.com is and I am not familiar with their API, but this error message indicates that they do not have a service responding to requests at that URL (i.e. 'rpxnow.com/api/v2/auth_info').
Are you able to verify that their service is up and running at that URL?
尝试使用这个:
http://docs. python-requests.org/en/latest/user/quickstart/#make-a-post-request
Try using this:
http://docs.python-requests.org/en/latest/user/quickstart/#make-a-post-request
您误解了 httplib 的文档。实例化
HTTPSConnection
的参数只是主机名。然后,您将实际路径作为第二个参数传递给request
。所以:You've misunderstood the documentation to httplib. The parameter to instantiate the
HTTPSConnection
is just the hostname. You then pass the actual path as the second param torequest
. So: