Skip to content

Raise better exception if authentication error occurs #6

Description

@simonw

Got this traceback (my token was invalid):

  File "...python3.9/site-packages/github_contents.py", line 51, in read_large
    tree_entry = [t for t in default_tree["tree"] if t["path"] == filepath][0]
KeyError: 'tree'

Relevant code:

def read_large(self, filepath):
"Returns (file_contents_in_bytes, sha1)"
default_tree = self.session.get(
self.base_url() + "/git/trees/{}?recursive=1".format(self.branch),
headers=self.headers(),
).json()
try:
tree_entry = [t for t in default_tree["tree"] if t["path"] == filepath][0]
except IndexError:
raise self.NotFound(filepath)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions