Skip to content

Instantly share code, notes, and snippets.

@benjiao
Last active July 12, 2023 01:16
Show Gist options
  • Save benjiao/28dc36bd87121b3273e0b3e079a8e8d8 to your computer and use it in GitHub Desktop.
Save benjiao/28dc36bd87121b3273e0b3e079a8e8d8 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/")
@hassanseoul123
Copy link

How to get log of every retry?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment