Problem reading 'status' from response

Solved
Tod
Here to help

Problem reading 'status' from response

Sorry, I am new but am hoping this is the right place to ask this question.  I am attempting to write a script to check the device status of Meraki switches and Access Point per site.  The following code properly gets a response from the access points but I get a the following error on this line: print (status[0])['status']
TypeError: 'NoneType' object is not subscriptable

 

Can anyone explain why?

 
 
import requests
import meraki
import json
import os, glob
import time
import getpass

# Get what to Search for:
site = input("Site: ")
Merakikey = getpass.getpass("Enter Meraki API Key: ")

# Initialize Meraki API session
dashboard = meraki.DashboardAPI(Merakikey)

# Get organization ID
organizations = dashboard.organizations.getOrganizations()
org_id = organizations[0]['id']

# Get devices in the organization
devices = dashboard.organizations.getOrganizationDevices(org_id)

# Find devices at the specified site
for device in devices:

if site.lower() in device['name'].lower():
print(f"Device Name: {device['name']}")
print(f"Model: {device['model']}")
print(f"Serial Number: {device['serial']}")
print(f"Firmware Version: {device['firmware']}")
 
if 'MS' in device['model']: # Check if it's a switch
# Get switch status
#status = dashboard.devices.getDeviceStatuses(org_id, device['serial'])
#print(f"Operational Status: {status['status']}")
elif 'MR' in device['model']: # Check if it's an access point
# Get access point status
status = dashboard.organizations.getOrganizationDevicesStatuses(org_id,serials = device['serial'])
 
# Current issue - We get the status but are not able to extract the information or print it. I think it is
# a string/list/dictionary issue. Once that is resolved this should work. The line above does get a proper return from
# Meraki.
 
print (type(status))
print (status[0])['status']
# Above line gets the error
 
#print(f"Operational Status: {status['status']}")
#else:
#print("Device type not supported for status retrieval.")
 
#print("----------------------")
1 Accepted Solution
RaphaelL
Kind of a big deal
Kind of a big deal

What about 

 

print (status[0]['status'])

 

instead of  print (status[0])['status']

View solution in original post

2 Replies 2
RaphaelL
Kind of a big deal
Kind of a big deal

What about 

 

print (status[0]['status'])

 

instead of  print (status[0])['status']

PhilipDAth
Kind of a big deal
Kind of a big deal

Maybe try something like:

for s in status:
  print(s)

 

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.