Created
July 14, 2015 14:51
-
-
Save javierhonduco/0a4237166428506d45b1 to your computer and use it in GitHub Desktop.
requests_retry_on_5xx.py
This file contains 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.packages.urllib3.util import Retry | |
from requests.adapters import HTTPAdapter | |
from requests import Session | |
import requests | |
requests.packages.urllib3.disable_warnings() | |
MAX_RETRIES = 2 | |
session = Session() | |
session.mount("http", HTTPAdapter( | |
max_retries=Retry(total=MAX_RETRIES, status_forcelist=[500, 502, 503, 504]) | |
) | |
) | |
r = session.get('https://google.com/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment