【问题标题】:How to set path for PyGithub method?如何为 PyGithub 方法设置路径?
【发布时间】:2015-10-03 03:32:09
【问题描述】:

我正在使用 PyGithub 获得对我自己的 github 存储库的基本访问权限。大多数方法都需要一个“路径”,我不确定那是什么。我将在 .get_contents() 函数中使用哪些参数?简单例子:

    from github import Github
    g = Github("***","***")
    repo = g.get_user().get_repo("my_projects")
    contents = repo.get_contents()

【问题讨论】:

  • 您对上述 sn-p 的反应是什么?
  • 回溯错误;最后两行阅读:文件“/Library/Python/2.7/site-packages/PyGithub-1.25.2-py2.7.egg/github/Requester.py”,第177行,在__check raise self.__createException(status, responseHeaders , 输出) github.GithubException.UnknownObjectException: 404 {u'documentation_url': u'developer.github.com/v3', u'message': u'Not Found'}
  • 根据 pygithhub 的说法,产生上述异常的原因如下:请求不存在的对象时引发异常(当 Github API 回复 404 HTML 状态时)
  • repo 对象存在(我可以调用 repo.name 并获得“my_projects”而没有错误)。我需要弄清楚我认为应该在 get_contents() 中放入什么

标签: python github github-api pygithub


【解决方案1】:

您需要传递以下参数:

path - string - 内容路径。

ref - string - 提交/分支/标签的名称。默认:存储库的默认分支(通常是 master)

例如 - repo.get_contents('config/version.rb','development')

查看更多here

【讨论】:

    猜你喜欢
    • 2014-08-29
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    • 1970-01-01
    相关资源
    最近更新 更多