Skip to content

Commit 422c65e

Browse files
committed
ensure only specified https:// adapter is in session
1 parent 6482d63 commit 422c65e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/shared.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import sys
5+
from collections import OrderedDict
56
from datetime import datetime, timezone
67

78
# Third-party
@@ -33,14 +34,23 @@ def __init__(self, message, exit_code=None):
3334
super().__init__(self.message)
3435

3536

36-
def get_session(accept_header=None):
37-
"""Create a reusable HTTP session with retry logic."""
38-
session = Session()
37+
def get_session(accept_header=None, session=None):
38+
"""
39+
Create or configure a reusable HTTPS session with retry logic and headers.
40+
"""
41+
if session is None:
42+
session = Session()
43+
44+
# Purge default and custom session connection adapters
45+
# (With only a https:// adapter, below, unencrypted requests will fail.)
46+
session.adapters = OrderedDict()
3947

4048
retry_strategy = Retry(
4149
total=5,
4250
backoff_factor=10,
4351
status_forcelist=STATUS_FORCELIST,
52+
allowed_methods=["GET", "POST"],
53+
raise_on_status=False,
4454
)
4555
session.mount("https://", HTTPAdapter(max_retries=retry_strategy))
4656

0 commit comments

Comments
 (0)