1 回答

TA貢獻1836條經(jīng)驗 獲得超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/
添加回答
舉報