From 422c65e8332a688d7d32f6bebfbcc75320049624 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Fri, 7 Nov 2025 07:43:53 +0100 Subject: [PATCH 1/3] ensure only specified https:// adapter is in session --- scripts/shared.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/shared.py b/scripts/shared.py index c901b6d6..d7e4002e 100644 --- a/scripts/shared.py +++ b/scripts/shared.py @@ -2,6 +2,7 @@ import logging import os import sys +from collections import OrderedDict from datetime import datetime, timezone # Third-party @@ -33,14 +34,23 @@ def __init__(self, message, exit_code=None): super().__init__(self.message) -def get_session(accept_header=None): - """Create a reusable HTTP session with retry logic.""" - session = Session() +def get_session(accept_header=None, session=None): + """ + Create or configure a reusable HTTPS session with retry logic and headers. + """ + if session is None: + session = Session() + + # Purge default and custom session connection adapters + # (With only a https:// adapter, below, unencrypted requests will fail.) + session.adapters = OrderedDict() retry_strategy = Retry( total=5, backoff_factor=10, status_forcelist=STATUS_FORCELIST, + allowed_methods=["GET", "POST"], + raise_on_status=False, ) session.mount("https://", HTTPAdapter(max_retries=retry_strategy)) From 62ab4e1449a0cd511be8a79f372f1f82ad871331 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Fri, 7 Nov 2025 07:56:56 +0100 Subject: [PATCH 2/3] replace misleading import --- scripts/shared.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/shared.py b/scripts/shared.py index d7e4002e..c783fb4d 100644 --- a/scripts/shared.py +++ b/scripts/shared.py @@ -9,7 +9,8 @@ from git import InvalidGitRepositoryError, NoSuchPathError, Repo from pandas import PeriodIndex from requests import Session -from requests.adapters import HTTPAdapter, Retry +from requests.adapters import HTTPAdapter +from urllib3.util import Retry # Constants STATUS_FORCELIST = [ From b9ea5978c87b23422e01cbb3a6ef2faebc26a70f Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Fri, 7 Nov 2025 09:03:08 +0100 Subject: [PATCH 3/3] improve documentation and reduce backoff_factor to 3 --- scripts/shared.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/shared.py b/scripts/shared.py index c783fb4d..541988fc 100644 --- a/scripts/shared.py +++ b/scripts/shared.py @@ -37,7 +37,8 @@ def __init__(self, message, exit_code=None): def get_session(accept_header=None, session=None): """ - Create or configure a reusable HTTPS session with retry logic and headers. + Create or configure a reusable HTTPS session with retry logic and + appropriate headers. """ if session is None: session = Session() @@ -46,9 +47,11 @@ def get_session(accept_header=None, session=None): # (With only a https:// adapter, below, unencrypted requests will fail.) session.adapters = OrderedDict() + # Try again after 0s, 6s, 12s, 24s, 48s (total 90s) for the specified HTTP + # error codes (STATUS_FORCELIST) retry_strategy = Retry( total=5, - backoff_factor=10, + backoff_factor=3, status_forcelist=STATUS_FORCELIST, allowed_methods=["GET", "POST"], raise_on_status=False,