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)
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.cnblogs.com/shengulong/p/10989582.html