Created
November 1, 2022 05:48
-
-
Save chienhsiang-hung/2b246264255b7c2d2b86302a3bb7ac31 to your computer and use it in GitHub Desktop.
Retry in Requests
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
import logging | |
import requests | |
from requests.adapters import HTTPAdapter, Retry | |
logging.basicConfig(level=logging.DEBUG) | |
session = requests.Session() | |
retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504]) | |
session.mount('http://', HTTPAdapter(max_retries=retries)) | |
session.get('http://httpstat.us/503') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment