requests添加max_retries

import requests
from urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter

s = requests.Session()
retries = Retry(total=3,
                backoff_factor=0.1,
                status_forcelist=[ 500, 502, 503, 504 ])
s.mount('http://', HTTPAdapter(max_retries=retries))
s.mount('https://', HTTPAdapter(max_retries=retries))
s.get(request_url, params=data, headers=headers, verify=False, timeout=3)
s.post(request_url, data=json.dumps(data, separators=(',', ':')), headers=headers, verify=False, timeout=3)

参考:
https://stackoverflow.com/a/35504626
https://www.cnblogs.com/eshizhan/p/5072626.html

你可能感兴趣的:(Python,爬虫)