【问题标题】:When accessing a Rest API via requests.get it times out. Same URL gets the response in browser通过 requests.get 访问 Rest API 时超时。相同的 URL 在浏览器中得到响应
【发布时间】:2022-12-18 04:20:43
【问题描述】:

我正在尝试访问支持 GET、POST、PUT、MOVE 函数的 Rest API。当我尝试使用浏览器的 URL 获取文件列表时,我收到了来自 REST API 的响应。但是,当我尝试通过 requests.get(url) 调用相同的 URL 时,我得到:

(由 ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x000002D8CCFBC6A0>, 'Connection to timed out. (connect timeout=None)'))

我错过了什么? (如果有什么不同,我将在 URL 中传递 JWT 令牌)

#URL 在浏览器中返回一个 JSON 格式的列表

#当通过请求调用相同的URL时

import requests
url = https://wwww.restapi.com/content?JWT-token
x = requests.get(url)
print(x.status_code)

#错误输出: (由 ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x000002D8CCFBC6A0>, 'Connection to <URL> timed out. (connect timeout=None)'))

【问题讨论】:

    标签: python-3.x rest python-requests urllib


    【解决方案1】:
    class Coordinates:
        def distToPoint(self, p):
            """
            Use pythagoras to find distance
            (a^2 = b^2 + c^2)
            """
            ...
    
        def isNear(self, p):
            distToPoint(self, p)
            ...
    

    【讨论】:

    • 你回答错问题了吗?请在添加答案之前阅读您正在回答的问题。
    • 嗨 Vishwajeet,感谢您的回复。我不得不更改标题,因为它是上一个问题的遗留问题。我很感激,并对给您带来的不便深表歉意
    猜你喜欢
    • 2017-06-16
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 2011-09-14
    • 2013-09-28
    • 2015-03-15
    • 1970-01-01
    相关资源
    最近更新 更多