将github问题导出到csv [英] Exporting github issues to csv
问题描述
我试图将github问题的列表从存储库导出到csv,但我会遇到一些错误。我试过调查其他问题,但他们似乎并没有帮助我。我目前在SLES12 vm上使用python2.7.9。
I'm trying to export a list of github issues from a repository to csv, but i keep coming across a few errors. I've tried looking into it on other questions but they didn't seem to help me out. I'm currently using python2.7.9 on SLES12 vm.
def write_issues(response):
for issue in response.json():
labels = issue['labels']
for label in labels:
if label['name'] == "Client Requested":
csvout.writerow([issue['number'],
issue['title'].encode('utf-8'),
issue['body'].encode('utf-8'),
issue['created_at'],
issue['updated_at']])
$ b p>获取这些错误
getting these errors
Traceback (most recent call last):
File "export.py", line 50, in <module>
write_issues(r)
File "export.py", line 24, in write_issues
labels = issue['labels']
TypeError: string indices must be integers
推荐答案
response.json c $ c>绝对不包含issue字典的列表。您向无效或不正确的端点发出请求,或者点击速率限制 。在循环之前检查
response.json()
的实际值。
response.json()
definitely doesn't contain a list of "issue" dictionaries. You are either making a request to an invalid or incorrect endpoint, or hitting a rate limit. Check an actual value of response.json()
before the loop.
适用于我:
>>> import requests
>>>
>>> url = "https://api.github.com/repos/angular/protractor/issues"
>>> response = requests.get(url)
>>> for issue in response.json():
... labels = issue['labels']
... for label in labels:
... print label
...
{u'url': u'https://api.github.com/repos/angular/protractor/labels/type:%20docs', u'color': u'5319e7', u'name': u'type: docs'}
{u'url': u'https://api.github.com/repos/angular/protractor/labels/type:%20question', u'color': u'f7c6c7', u'name': u'type: question'}
{u'url': u'https://api.github.com/repos/angular/protractor/labels/type:%20feature%20request', u'color': u'009800', u'name': u'type: feature request'}
...
这篇关于将github问题导出到csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!