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
标签:retries,cookies,python,Max,url,exceeded,requests 来源: https://www.cnblogs.com/cuitang/p/15407448.html