Python code not continuing when using try / continue

DevilWAH
Here to help

Python code not continuing when using try / continue

I have the following code that I am trying to test, when some error happen it continues as expected I know some of the net works it will loop through are not wireless but rather than check each i just want to try and if it fails continue. But when i run it i get the below error and it stops? 
 
So to be clear i know why the call is failing and i expect that. But it is hitting the try: block, but rather than continue it stops the script? Why is this, other errors it continues with, is the the python library breaking out of the script and how can I over ride it. Yes i could always check that the network has wireless type but the "try" method would be nice to use. 
 
ERROR
wireless, getNetworkWirelessSsids - 400 Bad Request, {'errors': ['This endpoint only supports wireless networks']}
Meraki API error: wireless, getNetworkWirelessSsids - 400 Bad Request, {'errors': ['This endpoint only supports wireless networks']}
status code = 400
reason = Bad Request
error = {'errors': ['This endpoint only supports wireless networks']}
 
SCRIPT
     try:
            for net in networks:
                print (f'Checking network:  {net["name"]}')
                ssids = dashboard.wireless.getNetworkWirelessSsids(net["id"])
                ssid = next((item for item in ssids if item["name"] == "WSP Corporate"),None)
                ccount = dashboard.wireless.getNetworkWirelessClientCountHistory(net["id"], ssid=ssid["number"], timespan=86400)
                cfailed = dashboard.wireless.getNetworkWirelessFailedConnections(net["id"],ssid=ssid["number"], timespan=86400)
                #last step is to out put the details to a csv
                for item in cfailed:
                    #print (item["clientMac"] + "   " + item["serial"]+ "    " + item["failureStep"]+ "    " + item["type"] + "     " + item["ts"])
                    csvdata = (net["name"],ssid["name"],item["clientMac"],item["serial"],item["failureStep"],item["type"],item["ts"])
                    writer.writerow(csvdata)
        except meraki.APIError as e:
            print(f'Meraki API error: {e}')
            print(f'status code = {e.status}')
            print(f'reason = {e.reason}')
            print(f'error = {e.message}')
            csvdata = (net["name"],"ERROR","ERROR","ERROR","ERROR","ERROR","ERROR")
            writer.writerow(csvdata)
            continue
        except Exception as e:
            csvdata = (net["name"],"ERROR","ERROR","ERROR","ERROR","ERROR","ERROR")
            writer.writerow(csvdata)
            continue

 

1 Reply 1
DevilWAH
Here to help

Sorry I resolved it, needed to move the looping though networks out side the "try" as it was failing on one network and ending the loop, using "try" after the "for net in networks:" and it works as expected

Get notified when there are additional replies to this discussion.