Skip to content

Commit ea3803a

Browse files
committed
Use urlopen's context parameter instead of cafile
1 parent 5a03d0f commit ea3803a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/taskgraph/run-task/fetch-content

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import os
1818
import pathlib
1919
import random
2020
import re
21+
import ssl
2122
import stat
2223
import subprocess
2324
import sys
@@ -190,9 +191,11 @@ def stream_download(url, sha256=None, size=None, headers=None):
190191
req_headers[key.strip()] = val.strip()
191192

192193
req = urllib.request.Request(url, None, req_headers)
193-
with urllib.request.urlopen(
194-
req, timeout=60, cafile=certifi.where()
195-
) if certifi else urllib.request.urlopen(req, timeout=60) as fh:
194+
kwargs = {}
195+
if certifi:
196+
ssl_context = ssl.create_default_context(cafile=certifi.where())
197+
kwargs["context"] = context = ssl_context
198+
with urllib.request.urlopen(req, timeout=60, **kwargs) as fh:
196199
if not url.endswith(".gz") and fh.info().get("Content-Encoding") == "gzip":
197200
fh = gzip.GzipFile(fileobj=fh)
198201
else:

test/test_scripts_fetch_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def fetch_content_mod():
6060
def test_stream_download(
6161
monkeypatch, fetch_content_mod, url, sha256, size, headers, raises
6262
):
63-
def mock_urlopen(req, timeout=None, *, cafile=None):
63+
def mock_urlopen(req, timeout=None, *, context=None):
6464
assert req._full_url == url
6565
assert timeout is not None
6666
if headers:

0 commit comments

Comments
 (0)