当前位置:   article > 正文

Max retries exceeded with URL报错小记_青龙max retries exceeded with url

青龙max retries exceeded with url

from hyp
mistake:

  • 循环post请求第二遍报错 Max retries exceeded with URL
for i in fac:
	url=******
    payload = ********
	req = requests.request("POST", url, data=payload, headers=headers, timeout=3)
   *******
  • 1
  • 2
  • 3
  • 4
  • 5

网上查询的方法

  • 1、增加重试连接次数:
requests.DEFAULT_RETRIES = 5
  • 1
  • 2、关闭多余的链接:
s = requests.session()
s.keep_alive = False
  • 1
  • 2
  • 3、请求时增加缓冲延时
 time.sleep(60)
  • 1
  • 考虑了很多headers、timeout、链接活动问题,包括close()但都不是很有效.

解决方法

由于每次的第一次循环是通过的,二次post才报错,只要转变思路不将requests的生命周期延长到第二次循环。
所以只要将post封装成方法调用就行。

def post(value):
    headers = ******
    payload = ******
    url = ******
    req = requests.request("POST", url, data=payload, headers=headers, timeout=3)
    return req.text
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

注:平常代码写严谨一些才不会碰见很多奇葩错误

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/384456
推荐阅读
相关标签
  

闽ICP备14008679号