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算法