Response.json list indices must be integers or slices, not str [SOLVED] - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Response.json list indices must be integers or slices, not str [SOLVED] (/thread-35525.html) |
Response.json list indices must be integers or slices, not str [SOLVED] - AlphaInc - Nov-13-2021 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:47ZBut 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 strI have a similar request for another project where I want to get the name and this works fine. Can anyone help me? RE: Response.json list indices must be integers or slices, not str - snippsat - Nov-13-2021 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'])
RE: Response.json list indices must be integers or slices, not str - AlphaInc - Nov-13-2021 (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. Thank you that worked RE: Response.json list indices must be integers or slices, not str [SOLVED] - Lauraburmrs - Dec-15-2022 Hi, Thanks for trying out the API. Unfortunately at the moment developers don't support retrieving the latest commit date from GitHub. RE: Response.json list indices must be integers or slices, not str [SOLVED] - fullytotal - Mar-24-2023 In that sample data, yes. But clearly not always, otherwise it wouldn't be a list in the first place. |