Skip to content

Commit

Permalink
use a new Session for each request
Browse files Browse the repository at this point in the history
this attempts to work around an issue we see with requests to Opencast
possibly failing when re-using urllib https connections
  • Loading branch information
lbjay committed Dec 9, 2024
1 parent b1a834d commit dcee23f
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions functions/zoom-uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@
aws_lambda = boto3.client("lambda")
sqs = boto3.resource("sqs")

session = requests.Session()
session.auth = HTTPDigestAuth(OPENCAST_API_USER, OPENCAST_API_PASSWORD)
session.headers.update(
{
"X-REQUESTED-AUTH": "Digest",
# TODO: it's possible this header is not necessary for the endpoints
# being used here. It seems like for Opencast endpoints where the
# header *is* necessary the correct value is actually
# "X-Opencast-Matterhorn-Authorization"
"X-Opencast-Matterhorn-Authentication": "true",
}
)

UPLOAD_OP_TYPES = ["track", "uri-track"]


Expand All @@ -67,6 +54,16 @@ class InvalidOpencastSeriesId(Exception):
def oc_api_request(method, endpoint, **kwargs):
url = urljoin(OPENCAST_BASE_URL, endpoint)
logger.info({"url": url, "kwargs": kwargs})

session = requests.Session()
session.auth = HTTPDigestAuth(OPENCAST_API_USER, OPENCAST_API_PASSWORD)
session.headers.update(
{
"X-REQUESTED-AUTH": "Digest",
"X-Opencast-Matterhorn-Authentication": "true",
}
)

try:
resp = session.request(method, url, **kwargs)
except requests.RequestException:
Expand Down

0 comments on commit dcee23f

Please sign in to comment.