Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github.GithubException.UnknownObjectException: 404 {"message": "Not Found",

Full error:

File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/site-packages/github/Repository.py", line 2154, in update_file
    headers, data = self._requester.requestJsonAndCheck(
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/site-packages/github/Requester.py", line 353, in requestJsonAndCheck
    return self.__check(
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/site-packages/github/Requester.py", line 378, in __check
    raise self.__createException(status, responseHeaders, output)
github.GithubException.UnknownObjectException: 404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#create-or-update-file-contents"}
Error: Process completed with exit code 1.

I am trying to run a script from my github repo using github workflow which updates a file with new contents.

Here is the code:

g = Github(token)
repo = g.get_repo(repoName)
oldFile = repo.get_contents(oldFilePath)
repo.update_file(oldFile.path, "update file", updatedFile, oldFile.sha, branch="main")

Note: The script, .yml workflow file, and the file being updated are all in the same repo. This same code runs smoothly when I run it on my local machine. But the error occurs when its running via Github workflow.

.yml code:

- name: run .py file
    run: python script.py

Also note: The github token is accessed from the script with os.environ.get(TOKEN_SECRET_NAME)

like image 918
Sukanta Avatar asked Sep 05 '25 03:09

Sukanta


1 Answers

You are not passing secret token as env. Try below code

   - name: run .py file
     run: python script.py
     env:
        TOKEN_SECRET_NAME: ${{ secrets.token }}
like image 90
Sam-Sundar Avatar answered Sep 07 '25 21:09

Sam-Sundar