Skip to content

Instantly share code, notes, and snippets.

@jonathanhle
Forked from benjiao/requests-with-retry.py
Created May 29, 2019 00:40
Show Gist options
  • Save jonathanhle/6efe352f2e706b62cdc22f930c5273d8 to your computer and use it in GitHub Desktop.
Save jonathanhle/6efe352f2e706b62cdc22f930c5273d8 to your computer and use it in GitHub Desktop.
Python requests with retry
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