INNER CODE UNIT · Python
fetch_artifact
wolfSSL/wolfssl-examples · .github/scripts/ci_triage.py:130
def fetch_artifact(url):
"""Download an artifact zip.
The endpoint 302s to a pre-signed blob URL. urllib replays our Authorization
header onto it, the blob store then tries to authenticate with a GitHub token
and 401s -- so catch the redirect and fetch the Location with no auth.
Getting this wrong empties every result, which reads as "nothing failed".
"""
req = urllib.request.Request(url)
req.add_header("Authorization", f"Bearer {TOKEN}")
try:
with _NOREDIR.open(req, timeout=120) as r:
return r.read()
except urllib.error.HTTPError as e:
if e.code not in (301, 302, 303, 307, 308):
raise
loc = e.headers.get("Location")
if not loc: