Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "wherobots-python-dbapi"
version = "0.23.1"
version = "0.23.2"
description = "Python DB-API driver for Wherobots DB"
authors = [{ name = "Maxime Petazzoni", email = "max@wherobots.com" }]
requires-python = ">=3.10, <4"
Expand Down
15 changes: 13 additions & 2 deletions wherobots/db/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
threadsafety = 1
paramstyle: Final[str] = PARAM_STYLE

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


def gen_user_agent_header():
try:
Expand Down Expand Up @@ -135,9 +139,16 @@ def connect(
@tenacity.retry(
stop=tenacity.stop_after_delay(wait_timeout),
wait=tenacity.wait_exponential(multiplier=1, min=1, max=5),
retry=tenacity.retry_if_not_exception_type(
(requests.HTTPError, OperationalError)
retry=(
tenacity.retry_if_exception(
lambda e: (
isinstance(e, requests.HTTPError)
and e.response.status_code in TRANSIENT_HTTP_STATUS_CODES
)
)
| tenacity.retry_if_exception_type(tenacity.TryAgain)
),
reraise=True,
)
def get_session_uri() -> str:
r = requests.get(session_id_url, headers=headers)
Expand Down