07-23-2021 06:42 PM
This is more of a basic python question than anything.
Working through the Official Cert Guide for DevNet associate and in chapter 8 example 8-7 for the DNA center SDK I'm running into an issue. When looping through the devices with the (for DEVICE in DEVICES.response:) it is returning 3 additional devices that are not shown in figure 8-10 of chapter 8, with values of None. I can print this without the formatting, but python throws and exception when the formatting is present.
Now I was thinking I could avoid this exception with an additional if clause but for reasons I don't understand as of yet, python doesn't take the final (else:) with a following print statement.
First can someone please explain my error (specifically between lines 14 - 25)? Secondly is this the best method for working through this particular issue or should I just be doing error handling on the formatting exception? Thanks!
from dnacentersdk import api DNAC = api.DNACenterAPI(username='devnetuser', password='Cisco123!', base_url='https://sandboxdnac2.cisco.com/dna') DEVICES = DNAC.devices.get_device_list() print('{0:25s}{1:1}{2:45}{3:1}{4:15s}'.format('Device Name', '|', \ 'Device Type', '|', 'Up Time')) print('-'*95) for DEVICE in DEVICES.response: if DEVICE.hostname == None: pass elif DEVICE.type == None: pass elif DEVICE.upTime == None: pass else: print(('{0:25}{1:1}{2:45}{3:1}{4:15}'.format(DEVICE.hostname, \ '|', DEVICE.type, '|', DEVICE.upTime)) print('-'*95) CLIENTS = DNAC.clients.get_overall_client_health(timestamp='') print('{0:25s}{1:1}{2:45}{3:1}{4:15s}'.format('Client Category', '|', \ 'Number of Clients', '|', 'Clients Score')) print('-'*95) for CLIENT in CLIENTS.response: for score in CLIENT.scoreDetail: print('{0:25s}{1:1}{2:<45d}{3:1}{4:<15d}'.format( score.scoreCategory.value, '|', score.clientCount, '|', \ score.scoreValue)) print('-'*95)
Solved! Go to Solution.
08-01-2021 09:01 AM
@AFlack20 i would post this over in the devnet cert forum here --> https://learningnetwork.cisco.com/s/topic/0TO3i0000008jY5GAI/devnet-certifications-community
08-01-2021 09:01 AM
@AFlack20 i would post this over in the devnet cert forum here --> https://learningnetwork.cisco.com/s/topic/0TO3i0000008jY5GAI/devnet-certifications-community
08-02-2021 12:41 PM
Will do, Thanks!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide