cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
338
Views
0
Helpful
2
Replies

OCG DEVASC Chapter 8 DNA Center Python SDK Example 8-7

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)
1 ACCEPTED SOLUTION

Accepted Solutions
bigevilbeard
Cisco Employee
2 REPLIES 2
bigevilbeard
Cisco Employee
AFlack20
Beginner

Will do, Thanks!

Create
Recognize Your Peers
Content for Community-Ad