Skip to content

Asset download from a public repo fails without auth #3302

@aolieman

Description

@aolieman

The Release Asset download feature added in #3060 is currently broken for public repositories.

Steps to reproduce:

from github import Github

github = Github()
public_repo = github.get_repo("stellarcarbon/sorocarbon")
latest_release = public_repo.get_latest_release()
asset = latest_release.assets[0]
asset.download_asset(f"/tmp/{asset.name}")

It fails on:

del requestHeaders["Authorization"]

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/alex/.pyenv/versions/stellarcarbon-3.12/lib/python3.12/site-packages/github/GitReleaseAsset.py", line 163, in download_asset
    self._requester.getFile(self.url, path=path, chunk_size=chunk_size)
  File "/home/alex/.pyenv/versions/stellarcarbon-3.12/lib/python3.12/site-packages/github/Requester.py", line 901, in getFile
    _, _, stream_chunk_iterator = self.getStream(url, parameters, headers, cnx, chunk_size=chunk_size)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.pyenv/versions/stellarcarbon-3.12/lib/python3.12/site-packages/github/Requester.py", line 928, in getStream
    status, responseHeaders, output = self.__requestEncode(
                                      ^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/.pyenv/versions/stellarcarbon-3.12/lib/python3.12/site-packages/github/Requester.py", line 1098, in __requestEncode
    status, responseHeaders, output = self.__requestRaw(
                                      ^^^^^^^^^^^^^^^^^^
  File "/home/alex/.pyenv/versions/stellarcarbon-3.12/lib/python3.12/site-packages/github/Requester.py", line 1186, in __requestRaw
    del requestHeaders["Authorization"]
        ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'Authorization'

Apparently, the assumption that an Authorization header will be present is incorrect. I don't know which (if any) other features are impacted by this assumption. Could we simply pop the key, or check for its presence before deletion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions