爬虫重复请求超时

from retrying import retry 
def is_request_exception(e):
   return issubclass(type(e),RequestException)
 @retry(retry_on_exception=is_request_exception,wrap_exception=False, stop_max_attempt_number=10)
 def request_get(url, timeout=120):
   return requests.get(url, timeout=120)

需求就是每当出现request相关异常的时候,就自动重来,上限连接10次;

posted @ 2020-05-26 15:14  凯帅  阅读(230)  评论(0编辑  收藏  举报