【问题标题】:Creation of Server-to-Server call API in Django在 Django 中创建服务器到服务器调用 API
【发布时间】:2018-05-10 09:51:04
【问题描述】:
    POST /somelink
    Host: hostname
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101
    Firefox/47.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate, br
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 683
    Cookie: xxx
    Connection: keep-alive
    access_token=xxx

如何使用这些详细信息进行 api 调用? 我已经试过了:

payload={ "POST":"somelink",
                         "Host":"hostname",
                         "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0",
                         "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                         "Accept-Language":"en-US,en;q=0.5",
                         "Accept-Encoding":"gzip, deflate, br",
                         "Content-Type": "application/x-www-form-urlencoded",
                         "Content-Length": "683",
                         "Cookie":" xxx",
                         "Connection":"keep-alive",
                         "access_token":"xxx"}
                headers = {}
                r = requests.post(url, data=json.dumps(payload), headers=headers)

但如果我尝试这种方式,我会得到“Connection aborted.', gaierror(-2, 'Name or service not known”。 谁能帮我解决这个问题?

【问题讨论】:

标签: python django single-sign-on


【解决方案1】:

gaierror 表示 DNS 查找失败:What does this socket.gaierror mean?

这意味着 Python 无法将主机名解析为 IP 地址来发起请求。示例:

>>> from socket import gethostbyname
>>> gethostbyname('www.google.com')
'172.217.26.196'
>>> gethostbyname('www.wrongurlthatdoesnotexist.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 2022-11-30
    • 1970-01-01
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    相关资源
    最近更新 更多