0
    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()

我正在尝试获取修订数据形式的要点并以 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
4

1 回答 1

0

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

  1. 如果您使用的是 1.0 的 alpha 版本,您应该在您的对象上使用该commits()方法。my_gist(文档: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())
于 2017-02-03T12:59:50.173 回答