Skip to content

Crash when an asset doesn't exist (returns 404 response) #129

@einsteinx2

Description

@einsteinx2

I've just started using this tool to backup my Github account, including all starred repositories. I ran into an issue where somehow an asset link 404ed (not sure why that would happen as any asset should be available from Github). In this case, the script crashed on urllib.error.HTTPError: HTTP Error 404: Not Found and could not continue.

404 responses on assets should probably be handled the same way a 404 is handled on a repo, e.g. it should print that it's skipping that asset and continue.

For reference, here is the output:

Cloning reicast-emulator repository from https://*****:x-oauth-basic@github.com/reicast/reicast-emulator.git to /Users/bbaron/tmp/github-backup/starred/reicast/reicast-emulator/repository
Retrieving reicast/reicast-emulator issues
Requesting https://api.github.com/repos/reicast/reicast-emulator/issues?per_page=100&page=1&filter=all&state=open&since=2020-01-03T22%3A21%3A33Z
Requesting https://api.github.com/repos/reicast/reicast-emulator/issues?per_page=100&page=1&filter=all&state=closed&since=2020-01-03T22%3A21%3A33Z
Saving 0 issues to disk
Retrieving reicast/reicast-emulator pull requests
Requesting https://api.github.com/repos/reicast/reicast-emulator/pulls?per_page=100&page=1&filter=all&state=open&sort=updated&direction=desc
Requesting https://api.github.com/repos/reicast/reicast-emulator/pulls?per_page=100&page=1&filter=all&state=closed&sort=updated&direction=desc
Saving 0 pull requests to disk
Retrieving reicast/reicast-emulator milestones
Requesting https://api.github.com/repos/reicast/reicast-emulator/milestones?per_page=100&page=1&state=all
Saving 9 milestones to disk
Retrieving einsteinx2 labels
Requesting https://api.github.com/repos/reicast/reicast-emulator/labels?per_page=100&page=1
Writing 64 labels to disk
Retrieving reicast/reicast-emulator releases
Requesting https://api.github.com/repos/reicast/reicast-emulator/releases?per_page=100&page=1
Saving 7 releases to disk
Requesting https://api.github.com/repos/reicast/reicast-emulator/releases/18970705/assets?per_page=100&page=1
Requesting https://api.github.com/repos/reicast/reicast-emulator/releases/18607180/assets?per_page=100&page=1
Requesting https://api.github.com/repos/reicast/reicast-emulator/releases/18598619/assets?per_page=100&page=1
Requesting https://api.github.com/repos/reicast/reicast-emulator/releases/12856493/assets?per_page=100&page=1
Traceback (most recent call last):
  File "/Users/bbaron/.platformio/penv/bin/github-backup", line 1117, in <module>
    main()
  File "/Users/bbaron/.platformio/penv/bin/github-backup", line 1112, in main
    backup_repositories(args, output_directory, repositories)
  File "/Users/bbaron/.platformio/penv/bin/github-backup", line 752, in backup_repositories
    include_assets=args.include_assets or args.include_everything)
  File "/Users/bbaron/.platformio/penv/bin/github-backup", line 962, in backup_releases
    download_file(asset['url'], os.path.join(release_cwd, asset['name']), get_auth(args))
  File "/Users/bbaron/.platformio/penv/bin/github-backup", line 572, in download_file
    response = opener.open(request)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 563, in error
    result = self._call_chain(*args)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 755, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

I'm working on fixing this now and will submit a PR when I'm done. I'm new to Python, so it will probably take me a little while to figure out how to handle it properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions