Skip to content

Commit a5fd480

Browse files
authored
Merge pull request #55 from wherobots/peter/retry-transient-http-errors
fix: retry transient HTTP errors (502/503/504/429) during session polling
2 parents 5bcf9cf + 3044d56 commit a5fd480

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "wherobots-python-dbapi"
3-
version = "0.23.1"
3+
version = "0.23.2"
44
description = "Python DB-API driver for Wherobots DB"
55
authors = [{ name = "Maxime Petazzoni", email = "max@wherobots.com" }]
66
requires-python = ">=3.10, <4"

wherobots/db/driver.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
threadsafety = 1
4747
paramstyle: Final[str] = PARAM_STYLE
4848

49+
# HTTP status codes that indicate transient server-side issues and should be retried.
50+
# This follows the industry-standard set used by urllib3.util.Retry's status_forcelist.
51+
TRANSIENT_HTTP_STATUS_CODES = {429, 502, 503, 504}
52+
4953

5054
def gen_user_agent_header():
5155
try:
@@ -135,9 +139,16 @@ def connect(
135139
@tenacity.retry(
136140
stop=tenacity.stop_after_delay(wait_timeout),
137141
wait=tenacity.wait_exponential(multiplier=1, min=1, max=5),
138-
retry=tenacity.retry_if_not_exception_type(
139-
(requests.HTTPError, OperationalError)
142+
retry=(
143+
tenacity.retry_if_exception(
144+
lambda e: (
145+
isinstance(e, requests.HTTPError)
146+
and e.response.status_code in TRANSIENT_HTTP_STATUS_CODES
147+
)
148+
)
149+
| tenacity.retry_if_exception_type(tenacity.TryAgain)
140150
),
151+
reraise=True,
141152
)
142153
def get_session_uri() -> str:
143154
r = requests.get(session_id_url, headers=headers)

0 commit comments

Comments
 (0)