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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.