首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用pygithub编辑Gist?

如何用pygithub编辑Gist?
EN

Stack Overflow用户
提问于 2022-10-13 16:02:38
回答 1查看 26关注 0票数 0

我正在尝试使用pygithub库来编辑已经创建的gist,但是到目前为止我还没有做到这一点。

代码语言:javascript
复制
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")},
)

这将导致这些错误。

代码语言:javascript
复制
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"}
EN

回答 1

Stack Overflow用户

发布于 2022-10-14 14:21:13

对于任何发现这个问题的人,您都可以使用以下代码编辑文档。

代码语言:javascript
复制
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")},
    )

确保您的访问令牌能够访问所需的一切,您需要的不仅仅是访问。

这是我制作的一个视频,里面有关于如何编辑https://youtu.be/IzmkE15AkfY的更多信息。

下面是一个带有文件和示例的github:https://github.com/msubb/python-gist

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74058738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档