Skip to content

Commit

Permalink
Use urlopen's context parameter instead of cafile
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Dec 26, 2024
1 parent 5a03d0f commit 585cf5e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/taskgraph/run-task/fetch-content
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import os
import pathlib
import random
import re
import ssl
import stat
import subprocess
import sys
Expand Down Expand Up @@ -190,9 +191,11 @@ def stream_download(url, sha256=None, size=None, headers=None):
req_headers[key.strip()] = val.strip()

req = urllib.request.Request(url, None, req_headers)
with urllib.request.urlopen(
req, timeout=60, cafile=certifi.where()
) if certifi else urllib.request.urlopen(req, timeout=60) as fh:
kwargs = {}
if certifi:
ssl_context = ssl.create_default_context(cafile=certifi.where())
kwargs["context"] = context = ssl_context
with urllib.request.urlopen(req, timeout=60, **kwargs) as fh:
if not url.endswith(".gz") and fh.info().get("Content-Encoding") == "gzip":
fh = gzip.GzipFile(fileobj=fh)
else:
Expand Down

0 comments on commit 585cf5e

Please sign in to comment.