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)
具体算法含义见:https://www.jianshu.com/p/6b7d6f62f6e3