requests原生支持

import requests
from requests.adapters import HTTPAdapter

s = requests.Session()
# 重试次数为3
s.mount('http://', HTTPAdapter(max_retries=3))
s.mount('https://', HTTPAdapter(max_retries=3))
# 超时时间为5s
s.get('http://example.com', timeout=5)

requests使用的重试算法:BackOff(指数退避算法)

具体算法含义见:https://www.jianshu.com/p/6b7d6f62f6e3

相关文章:

  • 2021-12-10
  • 2021-12-14
  • 2022-12-23
  • 2021-12-19
  • 2022-01-07
  • 2021-12-18
  • 2021-10-06
猜你喜欢
  • 2022-12-23
  • 2022-02-14
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
相关资源
相似解决方案