1 回答

TA贡献1836条经验 获得超3个赞
您正在请求一个不存在的 url。因此,您会超时。
>>> requests.get('https://does-not-exist')
... (suppressed for clarity)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='does-not-exist', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f6b6dba7210>: Failed to establish a new connection: [Errno -2] Name or service not known'))
主机是您传入的url。您可以捕获异常并查看您传入的相同 url,但您将 url 传递给requests.get.
>>> try:
... requests.get('https://does-not-exist')
... except requests.exceptions.ConnectionError as error:
... print(error.request.url)
...
https://does-not-exist/
添加回答
举报