Cant print dissasembled name in Python 2.7

Hi Guys,

So I am trying to print the bus numbers in python. However when i go to access the dissabsembled name key it comes back with this error:

Traceback (most recent call last):
  File "C:\Python27\curl test", line 13, in <module>
TypeError: list indices must be integers, not str

any help would be appreciated here is my code:

 import requests, json
import os
url = ''
payload = ''

headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'Authorization': 'apikey ' }
r = requests.get(url, data=payload, headers=headers)

JSONData = json.loads(r.content)



Firstly when asking for help online you might want to remove your API key from your code - it’s not safe to be spreading it about :slight_smile:

Secondly, one of your problems is that stopEvents is a list, not an object. A list contains multiple objects, which means you need to select an object with an integer (number) like: JSONData['stopEvents'][0] (0 will get you the first item).

Thirdly, there are multiple disassembledNames, for different sections. I assume you want the parent’s disassembled name, which you can get like this:

If you want to see the disassembledName for each of the objects in the stopEvents, then iterate over stopEvents and replace the 0 with the number of the object you want.

[quote=“Lockie, post:2, topic:1134”]

Thank you very much big help!

1 Like