Created
February 18, 2021 20:02
-
-
Save jcaxmacher/8124298c897b03c98cccffef7b9f55ab to your computer and use it in GitHub Desktop.
Python Requests 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
from requests.adapters import HTTPAdapter | |
from requests.packages.urllib3.util.retry import Retry | |
def get_requests_retry_session(): | |
retries = Retry(total=5, backoff_factor=1, status_forcelist=[429, 500, 502, 503, 504]) | |
adapter = HTTPAdapter(max_retries=retries) | |
http = requests.Session() | |
http.mount("https://", adapter) | |
http.mount("http://", adapter) | |
return http |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment