0

I am trying to edit an already created gist using the pygithub library but I have been unable to do so thus far.

import github.InputFileContent
from github import Github

g = Github("priv key")

gist = g.get_gist("004e205c856d5f934704333f5725d61e")
gist.edit(
    "Description edited by PyGithub",
    {"gistfile1.txt": github.InputFileContent("File also created by PyGithub")},
)

This results in these errors

Traceback (most recent call last):
  File "/Users/boazburnett/Library/Application Support/JetBrains/PyCharmCE2022.2/scratches/scratch.py", line 9, in <module>
    {"gistfile1.txt": github.InputFileContent("File also created by PyGithub")},
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/github/Gist.py", line 259, in edit
    "PATCH", self.url, input=post_parameters
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/github/Requester.py", line 355, in requestJsonAndCheck
    verb, url, parameters, headers, input, self.__customConnection(url)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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/gists#update-a-gist"}

1 Answers1

0

For anyone that finds this question you can edit gists using the following code.

import github.InputFileContent
from github import Github

    g = Github("insert access token here")

    gist = g.get_gist("insert gist link here")
    gist.edit(
        "",
        {"gistfile1.txt": github.InputFileContent("hello world")},
    )

Make sure your access token has access to everything required, you need more then just gists access.

Here is a video I made with more info about how to edit the gists: https://youtu.be/IzmkE15AkfY

And here is a github with the files and an example: https://github.com/msubb/python-gist