-
-
Save jonathanhle/6efe352f2e706b62cdc22f930c5273d8 to your computer and use it in GitHub Desktop.
Python requests with retry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from requests.adapters import HTTPAdapter | |
from requests.packages.urllib3.util.retry import Retry | |
with requests.Session() as s: | |
retries = Retry( | |
total=10, | |
backoff_factor=0.2, | |
status_forcelist=[500, 502, 503, 504]) | |
s.mount('http://', HTTPAdapter(max_retries=retries)) | |
s.mount('https://', HTTPAdapter(max_retries=retries)) | |
r = s.post("http://google.com/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment