Skip to content

Commit

Permalink
Added urllib3 < 2.X compatibility for the Retry object
Browse files Browse the repository at this point in the history
Added matrix to test if it also works with urllib3 <2.x
  • Loading branch information
Marc-Antoine Hinse committed Oct 21, 2024
1 parent 4c583f3 commit 98b2d50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ jobs:
'3.11',
'3.12',
]
pip-override: [
'',
'pip install "urllib3<2"',
]
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: ${{ matrix.pip-override }}
- run: make test
- run: make lint
21 changes: 12 additions & 9 deletions flareio/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ def _create_session() -> requests.Session:
),
)

retry = Retry(
total=5,
backoff_factor=2,
status_forcelist=[429, 502, 503, 504],
allowed_methods={"GET", "POST"},
)

# Support for urllib3 < 2.X
if hasattr(Retry, "backoff_max"):
retry.backoff_max = 15

# Enable retries
session.mount(
"https://",
HTTPAdapter(
max_retries=Retry(
total=5,
backoff_factor=2,
status_forcelist=[429, 502, 503, 504],
allowed_methods={"GET", "POST"},
backoff_max=15,
)
),
HTTPAdapter(max_retries=retry),
)

return session
Expand Down

0 comments on commit 98b2d50

Please sign in to comment.