requests超时参数retry的使用
retrying模块的使用、
-
retrying模块的地址:https://pypi.org/project/retrying/
-
retrying 模块的使用
- 使用retrying模块提供的retry模块
- 通过装饰器的方式使用,让被装饰的函数反复执行
- retry中可以传入参数
stop_max_attempt_number,让函数报错后继续重新执行,达到最大执行次数的上限,如果每次都报错,整个函数报错,如果中间有一个成功,程序继续往后执行
# parse.py import requests from retrying import retry headers = {} @retry(stop_max_attempt_number=3) #最大重试3次,3次全部报错,才会报错 def test(url):
rsp = requests.get(url, proxies=proxy, timeout=5)

浙公网安备 33010602011771号