22import logging
33import os
44import sys
5+ from collections import OrderedDict
56from datetime import datetime , timezone
67
78# Third-party
89from git import InvalidGitRepositoryError , NoSuchPathError , Repo
910from pandas import PeriodIndex
1011from requests import Session
11- from requests .adapters import HTTPAdapter , Retry
12+ from requests .adapters import HTTPAdapter
13+ from urllib3 .util import Retry
1214
1315# Constants
1416STATUS_FORCELIST = [
@@ -33,20 +35,23 @@ def __init__(self, message, exit_code=None):
3335 super ().__init__ (self .message )
3436
3537
36- # def get_session(accept_header=None):
37- # """Create a reusable HTTP session with retry logic."""
38- # session = Session()
39-
40-
4138def get_session (accept_header = None , session = None ):
42- """Create or configure a reusable HTTP session
43- with retry logic and headers."""
39+ """
40+ Create or configure a reusable HTTPS session with retry logic and
41+ appropriate headers.
42+ """
4443 if session is None :
4544 session = Session ()
4645
46+ # Purge default and custom session connection adapters
47+ # (With only a https:// adapter, below, unencrypted requests will fail.)
48+ session .adapters = OrderedDict ()
49+
50+ # Try again after 0s, 6s, 12s, 24s, 48s (total 90s) for the specified HTTP
51+ # error codes (STATUS_FORCELIST)
4752 retry_strategy = Retry (
4853 total = 5 ,
49- backoff_factor = 10 ,
54+ backoff_factor = 3 ,
5055 status_forcelist = STATUS_FORCELIST ,
5156 allowed_methods = ["GET" , "POST" ],
5257 raise_on_status = False ,
0 commit comments