【发布时间】:2020-09-08 10:51:03
【问题描述】:
难以从 GitHub api 解析 json。我正在尝试用来自组织的所有回购来填充团队。我正在使用 myteamname 获取循环所需的 teamid,该循环使用 repo 名称填充团队。
import json
import requests
mytokenid = "xxx"
myorg = "xxx"
myteamname = "xxx"
headers = {
'Authorization': 'token %s' % mytokenid,
}
response = requests.get('https://api.github.com/orgs/{0}/teams/{1}'.format(myorg, myteamname), headers=headers)
teamidjson = json.loads(response.text)
myteamid = teamidjson(['id'])
g = Github(tokenid)
for repo in g.get_organization(myorg).get_repos():
myreponame = repo.name
response = requests.put('https://api.github.com/teams/{0}/repos/{1}/{2}'.format(myteamid, myorg, myreponame), headers=headers)
我收到此错误消息
File "githubteam.py", line 74, in <module>
myteamid = teamidjson(['id'])
TypeError: 'dict' object is not callable
【问题讨论】:
-
你有什么问题?
-
只有当我对 teamid 进行硬编码时,带有 for 循环的后半部分才有效。我想要使用的是从团队名称中提取 teamid 并使用它。我该怎么做?
-
您是否要将其添加到问题本身?您还应该从响应中添加 JSON。
标签: python json github github-api