0

Having difficulty parsing json from GitHub api. I'm trying to populate a team with all the repos from an organisation. I'm using myteamname to obtain the teamid required for the loop which populates the team with the repo names.

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)

I get this error message

  File "githubteam.py", line 74, in <module>
    myteamid = teamidjson(['id'])
TypeError: 'dict' object is not callable
3
  • What's your question? Commented May 21, 2020 at 17:56
  • The second half with the for loop works only if I hardcode the teamid. What I want to do use is to extract the teamid from the team name and use that instead. How can I do that? Commented May 21, 2020 at 18:02
  • Are you goingbto add that to the question itself? You should also add the JSON from the response. Commented May 21, 2020 at 18:07

2 Answers 2

1

myteamid = teamidjson(['id'])

That seems to be causing the error. The correct way to access the id key is:

myteamid = teamidjson['id']

Sign up to request clarification or add additional context in comments.

Comments

1

I think you meant

myteamid = teamidjson['id']

# you can also use this
myteamid = teamidjson.get('id', None) # it will default to None if id doesn't exist...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.