【发布时间】:2015-08-31 18:48:13
【问题描述】:
我正在尝试在存储库中列出拉取请求的标题和编号。我想将 JSON 作为 dict 返回并打印拉取请求的标题和编号。
如果我只打印标题或编号,我会得到预期的输出,但如果将这些值组合起来打印,我会得到TypeError: string indices must be integers。
#!/usr/bin/env python
import github3
from github3 import login, GitHub
import requests
import json
import sys
auth = dict(username="xxxxxxxxx",token="xxxxxxxxx")
gh = login(**auth)
result = gh.repository(owner="xxx", repository="xxxx").pull_request(x)
data = result.as_dict()
print data['title']['number']
【问题讨论】:
-
我不熟悉这个 API,但我建议
data['title']是一个字符串,而不是你想象的字典。因此,您正在做类似'hello'['number']的事情,我希望您同意这是没有意义的。
标签: python python-2.7 github3.py