python requests.post Max retries exceeded with url 報錯

西北逍遥發表於2024-03-20

python requests.post Max retries exceeded with url 報錯

import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
 
session = requests.Session()
retries = Retry(total=5, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
session.mount('http://', HTTPAdapter(max_retries=retries))
session.mount('https://', HTTPAdapter(max_retries=retries))
 
response = session.post('http://example.com', data={'key': 'value'})

response = requests.post('http://example.com', data={'key': 'value'}, timeout=10)

##################

相關文章