Skip to content

Commit 585cf5e

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

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
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:

0 commit comments

Comments
 (0)