Skip to content

Raise better exception if authentication error occurs #6

@simonw

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)

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