【发布时间】:2020-10-18 08:20:00
【问题描述】:
我正在尝试使用 GitHub 的 JSON API 来提取包含受让人的所有拉取请求的列表(这样我就可以向他们发送消息以解决他们的拉取请求)。
我觉得我很接近以下代码,但也许我没有正确解析 JSON?任何帮助将不胜感激。
import requests
url = "https://api.github.com/repos/<repo>/<repoguide>/pulls?"
payload = {}
headers = {
'Authorization': 'Bearer <mastertoken>',
'Accept': 'application/vnd.github.v3+json',
'page': 'page=5&per_page=100'
}
response = requests.request("GET", url, headers=headers, data = payload)
response = requests.get(url).json()
for obj in response:
assignees = obj['assignees']
for assignee in assignees :
name = assignee['login']
url = obj['html_url']
print('/md Hello {0}, there is a GitHub issue that needs your attention. For more information see [here]({1}).'.format(name,url))
错误:
assignees = obj['assignees']
TypeError: string indices must be integers
我不明白这个错误是什么意思或如何解决它。它是拉字符串还是字典?抱歉,这是我第一次写代码。
【问题讨论】:
标签: python json api parsing github