/home 出现 gai 错误 [Errno -2] 名称或服务未知

发布于 2024-12-23 17:24:42 字数 1450 浏览 3 评论 0原文

根据 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 技术交流群。

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

发布评论

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

评论(3

勿忘初心 2024-12-30 17:24:43

我不知道 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?

拍不死你 2024-12-30 17:24:43

尝试使用这个:

http://docs. python-requests.org/en/latest/user/quickstart/#make-a-post-request

import requests

payload = {'apiKey':'somevalue', 'token':'some_token'}
r = requests.post('https://rpxnow.com/api/v2/auth_info', data=payload)
r.content

Try using this:

http://docs.python-requests.org/en/latest/user/quickstart/#make-a-post-request

import requests

payload = {'apiKey':'somevalue', 'token':'some_token'}
r = requests.post('https://rpxnow.com/api/v2/auth_info', data=payload)
r.content
泪之魂 2024-12-30 17:24:42

您误解了 httplib 的文档。实例化 HTTPSConnection 的参数只是主机名。然后,您将实际路径作为第二个参数传递给 request。所以:

connection = httplib.HTTPSConnection('rpxnow.com')
connection.request('POST', '/api/v2/auth_info', params)

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 to request. So:

connection = httplib.HTTPSConnection('rpxnow.com')
connection.request('POST', '/api/v2/auth_info', params)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文