Python Forum

Full Version: Response.json list indices must be integers or slices, not str [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everybody,

I try to get the latest commit date from GitHub by using the GitHub API. This is the code I use:

import requests

response = requests.get("https://api.github.com/repos/quietvoid/dovi_tool/commits")
print(response.json()["date"])
I hoped to get the output:

2021-11-10T03:39:47Z
But I get the following:

Traceback (most recent call last):
  File "/home/pi/debug.py", line 4, in <module>
    print(response.json()["date"])
TypeError: list indices must be integers or slices, not str
I have a similar request for another project where I want to get the name and this works fine.
Can anyone help me?
Like this,you most look at return(is now a Python dictionary) and the parse out where date is.
import requests

response = requests.get("https://api.github.com/repos/quietvoid/dovi_tool/commits")
json_resp = response.json()
#print(json_resp) # All response return
print(json_resp[0]['commit']['author']['date'])
Output:
2021-11-10T03:39:47Z
(Nov-13-2021, 12:40 PM)snippsat Wrote: [ -> ]Like this,you most look at return(is now a Python dictionary) and the parse out where date is.
import requests

response = requests.get("https://api.github.com/repos/quietvoid/dovi_tool/commits")
json_resp = response.json()
#print(json_resp) # All response return
print(json_resp[0]['commit']['author']['date'])
Output:
2021-11-10T03:39:47Z

Thank you that worked
Hi,
Thanks for trying out the API. Unfortunately at the moment developers don't support retrieving the latest commit date from GitHub.
In that sample data, yes. But clearly not always, otherwise it wouldn't be a list in the first place.