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
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("----------------------")