Python Forum
Response.json list indices must be integers or slices, not str [SOLVED]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Response.json list indices must be integers or slices, not str [SOLVED]
#1
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?
Reply
#2
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
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] Sort list paul18fr 5 947 Aug-18-2021, 06:34 AM
Last Post: naughtyCat
Question convert unlabeled list of tuples to json (string) masterAndreas 4 3,018 Apr-27-2021, 10:35 AM
Last Post: masterAndreas
  JSON response from REST service get nested value nl2ttl 2 1,107 Nov-30-2020, 09:34 PM
Last Post: nl2ttl
  TypeError: string indices must be integers hendern 2 1,414 Oct-02-2020, 10:16 PM
Last Post: hendern
  parser json response absolut 4 1,197 Sep-15-2020, 12:10 PM
Last Post: buran
  list indices must be integers or slices, not lists error djwilson0495 2 1,440 Aug-27-2020, 06:13 PM
Last Post: deanhystad
  Compare response and name list in experiment knoxvillerailgrind 3 1,057 Jul-26-2020, 12:23 PM
Last Post: deanhystad
  Empty response to request causing .json() to error t4keheart 1 1,932 Jun-26-2020, 08:35 PM
Last Post: bowlofred
  [Solved]TypeError: list indices must be integers or slices, not str NectDz 3 2,310 Jun-02-2020, 08:21 AM
Last Post: DreamingInsanity
  HELP: String indices must be integers animrehrm 6 2,038 May-17-2020, 02:18 PM
Last Post: animrehrm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020