From fdef4951a253b7c6f3ae991d1b29e36fd392b51b Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Mon, 12 Aug 2024 15:11:42 +0200 Subject: [PATCH] Use unredirected headers --- tools/build/package | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/build/package b/tools/build/package index 4aec5c6..1fd8639 100755 --- a/tools/build/package +++ b/tools/build/package @@ -46,19 +46,17 @@ def _read_manifest(path, platform, versions): def _download_artifact(uri) -> io.BytesIO: - headers = {} - # Add auth headers if the github token is available, on the build servers it is, but when running locally it is not. # Some operations do not require authentication but we do it anyway to avoid API call rate problems + request = urllib.request.Request(url=uri) + request.add_unredirected_header(key="Accept", val="application/vnd.github+json") if 'GITHUB_TOKEN' in os.environ: GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] - headers = {'Authorization': f'token {GITHUB_TOKEN}'} + request.add_unredirected_header(key="Authorization", val=f"Bearer {GITHUB_TOKEN}") print(' Downloading with authorization') else: print(' Downloading without authorization') - - req = urllib.request.Request(uri, headers=headers) - with urllib.request.urlopen(req) as response: + with urllib.request.urlopen(request) as response: data = response.read() assert (data) return io.BytesIO(data)