【问题标题】:Getting revisions data from Github gist从 Github gist 获取修订数据
【发布时间】:2017-06-20 08:47:10
【问题描述】:
    gist_ids = 'abc'

    def main():
        gh = github3.login (
            token=os.environ.get('my_token'),
            url='  ')
        my_gist = gh.gist(gist_ids)

        resp = github3.gists.history.GistHistory( json, session=None)

        print json.dumps(resp)
   if __name__ == '__main__':
    main()

我正在尝试获取修订数据表单 gist 并以 json 的形式存储。

python apis 新手请各位大神指点

Error:

Traceback (most recent call last):
  File "push.py", line 51, in <module>
    main()
  File "push.py", line 26, in main
    resp = github3.gists.history.GistHistory( json, session=None)
NameError: global name 'json' is not defined

【问题讨论】:

  • 您需要在文件顶部import json
  • @Amber 导入 json Traceback (most recent call last): File "push.py", line 52, in &lt;module&gt; main() File "push.py", line 27, in main resp = github3.gists.history.GistHistory( json, session=None) File "/Library/Python/2.7/site-packages/github3/models.py", line 47, in __init__ self.etag = json.pop('ETag', None) AttributeError: 'module' object has no attribute 'pop'

标签: python github gist github3.py


【解决方案1】:

根据您安装的 github3.py 版本,您有两种选择:

  1. 如果您使用的是 1.0 的 alpha 版本,您应该在您的 my_gist 对象上使用 commits() 方法。 (文档:http://github3.readthedocs.io/en/develop/gists.html

  2. 如果您使用的是 0.9 系列版本,则应在同一对象上使用 iter_commits() 方法。 (文档:http://github3.readthedocs.io/en/stable/gists.html#github3.gists.gist.Gist.iter_commits

这些将大致像这样工作:

# 1.0.0a4
for gist_commit in my_gist.commits():
    # do stuff with previous version
# 0.9.6
for gist_commit in my_gist.iter_commits():
    # ...

或者

# 1.0.0a4
my_gist_history = list(my_gist.commits())
# 0.9.6
my_gist_history = list(my_gist.iter_commits())

【讨论】:

    猜你喜欢
    • 2011-08-20
    • 1970-01-01
    • 2021-05-28
    • 2015-04-27
    • 2020-04-23
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    相关资源
    最近更新 更多