Skip to content

Commit 122eb56

Browse files
committed
Fix error downloading assets
When downloading assets using a fine grained token you will get a "can't concat str to bytes" error. This is due to the fine grained token being concatenated onto bytes in the line: `request.add_header("Authorization", "Basic ".encode("ascii") + auth)` This is better handled in the function `_construct_request` so I changed the lines that construct the request in `download_file` to use the function `_construct_request` and updated the function signature to reflect that.
1 parent a0fdae3 commit 122eb56

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

github_backup/github_backup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,14 +777,19 @@ def redirect_request(self, req, fp, code, msg, headers, newurl):
777777
return request
778778

779779

780-
def download_file(url, path, auth):
780+
def download_file(url, path, auth, as_app=False, fine=False):
781781
# Skip downloading release assets if they already exist on disk so we don't redownload on every sync
782782
if os.path.exists(path):
783783
return
784784

785-
request = Request(url)
785+
request = _construct_request(per_page=100,
786+
page=1,
787+
query_args={},
788+
template=url,
789+
auth=auth,
790+
as_app=as_app,
791+
fine=fine)
786792
request.add_header("Accept", "application/octet-stream")
787-
request.add_header("Authorization", "Basic ".encode("ascii") + auth)
788793
opener = build_opener(S3HTTPRedirectHandler)
789794

790795
try:
@@ -1255,6 +1260,8 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F
12551260
asset["url"],
12561261
os.path.join(release_assets_cwd, asset["name"]),
12571262
get_auth(args),
1263+
as_app=True if args.as_app is not None else False,
1264+
fine=True if args.token_fine is not None else False
12581265
)
12591266

12601267

0 commit comments

Comments
 (0)