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
Downloading large files #661
Comments
I've run into this problem before too. In my case, since I always had the SHA of the blob, I just used However, To do the fallback, you need to know two pieces of information:
If |
Closed as |
I have the same problem and end up doing something along the line of.
file_contents = repo.get_contents(dir_name, ref=branch) then for file_content in file_contents:
try:
if file_content.encoding != 'base64':
# some error ...
# ok...
except GithubException:
# if file_content DOES NOT HAVE encoding, it is a large file
blob = repo.get_git_blob(file_content.sha)
# do something with blob If try:
res = repo.get_contents(path_name, ref=branch)
# ok, we have the content
except GithubException:
return get_blob_content(repo, branch, path_name) where def get_blob_content(repo, branch, path_name):
# first get the branch reference
ref = repo.get_git_ref(f'heads/{branch}')
# then get the tree
tree = repo.get_git_tree(ref.object.sha, recursive='/' in path_name).tree
# look for path in tree
sha = [x.sha for x in tree if x.path == path_name]
if not sha:
# well, not found..
return None
# we have sha
return repo.get_git_blob(sha[0]) Real code with error-checking is longer, but the idea is here. |
When get the blob, following code will be useful. blob = repo.get_git_blob(sha[0])
b64 = base64.b64decode(blob.content)
return b64.decode("utf8") Also, update file will also encounter with this problem. |
github.GithubException.UnknownObjectException: 404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#get-repository-content"} getting this error when trying to download a got repository files for master branch |
https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#create-or-update-file-contents Doesn't look like it affects update file – there's no distinction for different file sizes when updating file contents mentioned on the REST API, and I'm able to update the contents of files when they are >1MB. |
Using the
.get_contents()
method to try to download a large file raises the error:Is there a way of detecting this and passing over to another handler that can download the file?
For example, if something like this fails:
optionally revert to:
The text was updated successfully, but these errors were encountered: