TypeError: list indices must be integers or slices, not str

eroche
Getting noticed

TypeError: list indices must be integers or slices, not str

Ok trying to nicely list out the results but keep getting the "TypeError: list indices must be integers or slices, not str" error. The loop works in all my other scripts except this one. What am I missing? 

 

 

import meraki

API_KEY = 'key'

dashboard = meraki.DashboardAPI(API_KEY)

serial = 'sn'

ip = '8.8.8.8'

response = dashboard.devices.getDeviceLossAndLatencyHistory(

    serial, ip,

    t0 = '2024-07-07T00:00:00Z',

    t1 = '2024-08-06T23:59:59Z',

    #timespan = '2678400',

    resolution = '60',

    uplink = 'wan1',

    )

fields = ['startTs','endTs','lossPercent','latencyMs']

for field in fields:

    print (f"{field}: {response[field]}")

 

2 Replies 2
KH
Meraki Employee
Meraki Employee

Hey @eroche 

 

With some edits I was able to see a neat response: 

import meraki

API_KEY = 'apikey'

dashboard = meraki.DashboardAPI(API_KEY)

serial = 'sn'
ip = '8.8.8.8'

response = dashboard.devices.getDeviceLossAndLatencyHistory(
    serial,
    ip,
    t0='2024-07-07T00:00:00Z',
    t1='2024-08-06T23:59:59Z',
    # timespan = '2678400',
    resolution='60',
    uplink='wan1'
)

fields = ['startTs', 'endTs', 'lossPercent', 'latencyMs', 'goodput', 'jitter']

for entry in response:
    for field in fields:
        print(f"{field}: {entry[field]}")
    print('---')  # Separator for each entry

8375c780-1fe5-4afe-9643-96102778ee64.PNG

 

Let me know if this works for you or helps!

If you found this post helpful, please give it kudos. If my answer solved your problem, click "accept as solution" so that others can benefit from it
eroche
Getting noticed

Hi @KH 

 

That worked!

 

Why did the nested loop work instead of what I had? Also the goodput field, is that the throughput/bandwidth on the uplink?

 

Thanks!

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.