簡體   English   中英

如何解決python請求錯誤:“Max retries exceeded with url”

[英]How solve python requests error: “Max retries exceeded with url”

我有以下代碼:

res = requests.get(url)

我使用多線程方法會出現以下錯誤:

ConnectionError: HTTPConnectionPool(host='bjtest.com', port=80): Max retries exceeded with url: /rest/data?method=check&test=123 (Caused by: [Errno 104] Connection reset by peer)

我已經使用了follow方法,但它仍然有錯誤:

s = requests.session()
s.keep_alive = False

或者

res = requests.get(url, headers={'Connection': 'close'})

那么,我應該怎么辦呢?

順便說一句, url是可以的,但是只能在內部訪問,所以url沒有問題。 謝謝!

你在 Mac 上運行你的腳本? 我也遇到了類似的問題,你可以執行 ulimit -n 來檢查一次可以處理多少個文件。

您可以使用下面的放大配置。

resource.setrlimit(resource.RLIMIT_NOFILE, (the number you reset,resource.RLIM_INFINITY))

希望能幫到你。

我的博客與您的問題相關

在此處輸入圖片說明

我有一個類似的案例,希望可以為您節省一些時間:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8001): Max retries exceeded with url: /enroll/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10f96ecc0>: Failed to establish a new connection: [Errno 61] Connection refused'))

問題實際上很愚蠢……本地主機在端口 8001 上關閉了! 重啟服務器解決了。

錯誤消息(誠然有點令人困惑)實際上意味着requests根本無法連接到您請求的 URL。

在這種情況下,這是因為您的urlhttp://bjtest.com/rest/data?method=check&test=123 ,這不是真正的網站。

它與您提出請求的格式無關。修復您的url ,它應該(大概)適合您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM