Authored by Bruno Duyé

Use of requests session and Retry

How to make an error resistant get or post, with many retries.

Usage: once requests_session object is initialized:

response =, json={...})
response = requests_session.get(url)
python 692 Bytes
  • I put the whole code for convenience:

    from requests import Session
    from requests.adapters import HTTPAdapter
    from urllib3.util import Retry
    requests_retry = Retry(total=12, backoff_factor=2, status_forcelist=[
                           429, 500, 501, 502, 503, 504], method_whitelist=False)
    requests_session = Session()
    requests_session.mount('http://', HTTPAdapter(max_retries=requests_retry))
    requests_session.mount('https://', HTTPAdapter(max_retries=requests_retry))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment