Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise better exception if authentication error occurs #6

Open
simonw opened this issue Feb 24, 2021 · 0 comments
Open

Raise better exception if authentication error occurs #6

simonw opened this issue Feb 24, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Feb 24, 2021

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)

@simonw simonw added the enhancement New feature or request label Feb 24, 2021
@simonw simonw changed the title Raise exception if error occurs Raise better exception if authentication error occurs Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant