1

I am trying to use GitHub's JSON API to pull in a list of all pull requests that contain assignees (so I can send them a message to resolve their pull requests).

I feel like I am close with the following code, but maybe I am not parsing the JSON correctly? any help would be appreciated.

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))

Error:

    assignees = obj['assignees']
TypeError: string indices must be integers

I don't understand what this error means or how to resolve it. Is it pulling a string vs dictionary? Sorry, this is my first time writing code.

1 Answer 1

1

As explained here, if you get "string indices must be integers" on obj['assignees'], it means obj is a string, not a dictionary.

Since a similar error was tricky to be reproduced, I would print, for debug, the value of response, to check its nature.

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

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.