PyGithub
PyGithub copied to clipboard
GithubException 422 when try to update a file in the Github repository.
Hi!, I get the follow error message when try to update a file in the repository:
github.GithubException.GithubException: 422 {"message": "Invalid request.\n\n"sha" wasn't supplied.", "documentation_url": "https://docs.github.com/rest/reference/repos#create-or-update-file-contents"}.
I attach a screenshot of the code
.
I can't reproduce your error. I tried the same operations with a test repository of mine and I manage to both create a new file and update it. So I'm not sure the bug is in PyGithub here but it could be in your code.
The block you posted is cut and the stacktrace is missing, but I assume the error is raised at line 627 by update_file, correct?
Try shrinking that blob and update one file manually, and verify if the error is still raised.
Yes, the error is raised at line 627. The code is cutted becuase this is a method in a class, the only things that I've cutted for this method is the instruction to instantiate the github object (with token). I tried to update using the github REST API directly (using requests in Python) and everything seems to work fine.
Try and do the same call with GitPython instead of using the script above, and post the possible error raised, if any. Is it only one particular file that raises the exception or immediately the first attempt of update? I can print all the sha from every file in that folder. Pay attention also to API rate limits: there are more than 2k files (so in your script above you make more than 2k calls)