python requests發起請求,報“Max retries exceeded with url”


需要高頻率重復調用一個接口,偶爾會出現“Max retries exceeded with url”

在使用requests多次訪問同一個ip時,尤其是在高頻率訪問下,http連接太多沒有關閉導致的
Max retries exceeded with url 的錯誤

解決方法:調用完之后,將連接關閉

            try:
                if type == 'JSON':
                    res = requests.post(url, headers=headers, json=parm, cookies=cookies)
                else:
                    res = requests.post(url, headers=headers, data=parm, cookies=cookies)
                logger.info('send_request_json_data_發起post請求,url為:{0},接口傳入的參數:{1}'.format(url, parm))
                # 請求完成后,關閉連接(若對同一個request高頻率發起時,可能會出現Max retries exceeded with url)
                res.close()
            except requests.RequestException as e:
                logger.error("send_request_json_data_post請求出現異常:{0}".format(e))

經過觀察發現,使用后關閉res.close(),可以解決Max retries exceeded with url 的錯誤

參考:https://blog.csdn.net/weixin_43932214/article/details/89554963?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM