Skip to content

Instantly share code, notes, and snippets.

@javierhonduco
Created July 14, 2015 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javierhonduco/0a4237166428506d45b1 to your computer and use it in GitHub Desktop.
Save javierhonduco/0a4237166428506d45b1 to your computer and use it in GitHub Desktop.
requests_retry_on_5xx.py
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