From 122eb56aa11c0878471f96aab63aaa3621a6e2e9 Mon Sep 17 00:00:00 2001 From: dale-primer-e <70494025+dale-primer-e@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:55:20 +1300 Subject: [PATCH] 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. --- github_backup/github_backup.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 562313a..49e54a6 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -777,14 +777,19 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler): return request -def download_file(url, path, auth): +def download_file(url, path, auth, as_app=False, fine=False): # Skip downloading release assets if they already exist on disk so we don't redownload on every sync if os.path.exists(path): return - request = Request(url) + request = _construct_request(per_page=100, + page=1, + query_args={}, + template=url, + auth=auth, + as_app=as_app, + fine=fine) request.add_header("Accept", "application/octet-stream") - request.add_header("Authorization", "Basic ".encode("ascii") + auth) opener = build_opener(S3HTTPRedirectHandler) try: @@ -1255,6 +1260,8 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F asset["url"], os.path.join(release_assets_cwd, asset["name"]), get_auth(args), + as_app=True if args.as_app is not None else False, + fine=True if args.token_fine is not None else False )