Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dealing with HTTPSConnectionPool errors in requests with adapters and backoff
# this snippet will deal with errors like HTTPSConnectionPool: Max retries exceeded with url...
# by using a backoff factor
# further reading:
# - docs:
# - stack overflow issue:
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment