I was going through Nick Russo’s course Getting Started with Software Development Using Cisco DevNet at Pluralsight and one thing he went through was interacting with the DNA Center API. Using a call to /intent/api/v1/network-device, DNA-C will return a JSON object consisting of an array of objects, or in Python speak, a list of dictionaries. This looks something like below, snipped for brevity:

{
    "response": [
        {
            "memorySize": "3735220224",
            "family": "Wireless Controller",
            "type": "Cisco 3504 Wireless LAN Controller",
            "macAddress": "50:61:bf:57:2f:00",
            "softwareType": "Cisco Controller",
            "softwareVersion": "8.8.111.0",
            "deviceSupportLevel": "Supported",
            "platformId": "AIR-CT3504-K9",
            "reachabilityFailureReason": "",
            "series": "Cisco 3500 Series Wireless LAN Controller",
            "serialNumber": "FCW2218M0B1",
            "inventoryStatusDetail": "<status><general code=\"SUCCESS\"/></status>",
            "hostname": "3504_WLC",
            "lastUpdateTime": 1596457941780,
            "errorDescription": null,
            "interfaceCount": "0",
            "lastUpdated": "2020-08-03 12:32:21",
            "lineCardCount": "0",
            "lineCardId": "",
            "locationName": null,
            "managementIpAddress": "10.10.20.51",
            "reachabilityStatus": "Reachable",
            "snmpContact": "",
            "snmpLocation": "",
            "tagCount": "0",
            "tunnelUdpPort": "16666",
            "waasDeviceMode": null,
            "apManagerInterfaceIp": "",
            "associatedWlcIp": "",
            "bootDateTime": "2020-03-12 16:08:21",
            "collectionStatus": "Managed",
            "errorCode": null,
            "roleSource": "AUTO",
            "upTime": "143 days, 20:24:58.00",
            "location": null,
            "role": "ACCESS",
            "collectionInterval": "Global Default",
            "instanceTenantId": "5e5a432575161200cc4ac95c",
            "instanceUuid": "72dc1f0a-e4da-4ec3-a055-822416894dd5",
            "id": "72dc1f0a-e4da-4ec3-a055-822416894dd5"
        },
        {
            "memorySize": "NA",
            "family": "Switches and Hubs",
            "type": "Cisco Catalyst 9300 Switch",
            "macAddress": "00:72:78:54:d1:00",
            "softwareType": "IOS-XE",
            "softwareVersion": "16.6.4a",
            "deviceSupportLevel": "Supported",
            "platformId": "C9300-48U",
            "reachabilityFailureReason": "",
            "series": "Cisco Catalyst 9300 Series Switches",
            "serialNumber": "FCW2214L0VK",
            "inventoryStatusDetail": "<status><general code=\"SUCCESS\"/></status>",
            "hostname": "leaf1",
            "lastUpdateTime": 1596459822923,
            "errorDescription": null,
            "interfaceCount": "0",
            "lastUpdated": "2020-08-03 13:03:42",
            "lineCardCount": "0",
            "lineCardId": "",
            "locationName": null,
            "managementIpAddress": "10.10.20.81",
            "reachabilityStatus": "Reachable",
            "snmpContact": "",
            "snmpLocation": "",
            "tagCount": "0",
            "tunnelUdpPort": null,
            "waasDeviceMode": null,
            "apManagerInterfaceIp": "",
            "associatedWlcIp": "",
            "bootDateTime": "2020-02-27 15:29:42",
            "collectionStatus": "Managed",
            "errorCode": null,
            "roleSource": "AUTO",
            "upTime": "157 days, 21:34:16.15",
            "location": null,
            "role": "ACCESS",
            "collectionInterval": "Global Default",
            "instanceTenantId": "5e5a432575161200cc4ac95c",
            "instanceUuid": "3dd27ed6-44f9-486d-abaf-a779781431a0",
            "id": "3dd27ed6-44f9-486d-abaf-a779781431a0"
        }
    ],
    "version": "1.0"
}

Nick then had some code to grab the management IP and ID of the device:

if get_resp.ok:
        for device in get_resp.json()["response"]:
            print(f"ID: {device['id']}  IP: {device['managementIpAddress']}")

I had some issues understanding the code so I decided to spend some time here and dive into it. The requests library is used to make the API call. When using requests, the response is going to be byte-encoded and not JSON-encoded. I wrote a few lines of Python to demonstrate this:

print(get_resp)
    print(type(get_resp))
    for line in get_resp:
        print(line)

This generates the following output:

daniel@devasc:~/DevAsc/nrusso$ python3 test.py 
<Response [200]>
<class 'requests.models.Response'>
b'{"response":[{"memorySize":"3735220224","family":"Wireless Controller","type":"Cisco 3504 Wireless LAN Controller","macAddress":'
b'"50:61:bf:57:2f:00","softwareType":"Cisco Controller","softwareVersion":"8.8.111.0","deviceSupportLevel":"Supported","platformId'
b'":"AIR-CT3504-K9","reachabilityFailureReason":"","series":"Cisco 3500 Series Wireless LAN Controller","serialNumber":"FCW2218M0B'
b'1","inventoryStatusDetail":"<status><general code=\\"SUCCESS\\"/></status>","hostname":"3504_WLC","lastUpdateTime":1596501161400,"'
b'errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCount":"0","lineCardId":"","locationNam'
b'e":null,"managementIpAddress":"10.10.20.51","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":"","tagCount":"0","'
b'tunnelUdpPort":"16666","waasDeviceMode":null,"apManagerInterfaceIp":"","associatedWlcIp":"","bootDateTime":"2020-03-12 16:06:41"'
b',"collectionStatus":"Managed","errorCode":null,"roleSource":"AUTO","upTime":"144 days, 8:26:01.00","location":null,"role":"ACCES'
b'S","collectionInterval":"Global Default","instanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid":"72dc1f0a-e4da-4ec3-a055-8'
b'22416894dd5","id":"72dc1f0a-e4da-4ec3-a055-822416894dd5"},{"memorySize":"NA","family":"Switches and Hubs","type":"Cisco Catalyst'
b' 9300 Switch","macAddress":"00:72:78:54:d1:00","softwareType":"IOS-XE","softwareVersion":"16.6.4a","deviceSupportLevel":"Support'
b'ed","platformId":"C9300-48U","reachabilityFailureReason":"","series":"Cisco Catalyst 9300 Series Switches","serialNumber":"FCW22'
b'14L0VK","inventoryStatusDetail":"<status><general code=\\"SUCCESS\\"/></status>","hostname":"leaf1","lastUpdateTime":1596520229779'
b',"errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 05:50:29","lineCardCount":"0","lineCardId":"","locationN'
b'ame":null,"managementIpAddress":"10.10.20.81","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":"","tagCount":"0"'
b',"tunnelUdpPort":null,"waasDeviceMode":null,"apManagerInterfaceIp":"","associatedWlcIp":"","bootDateTime":"2020-02-27 15:29:29",'
b'"collectionStatus":"Managed","errorCode":null,"roleSource":"AUTO","upTime":"158 days, 14:21:02.24","location":null,"role":"ACCES'
b'S","collectionInterval":"Global Default","instanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid":"3dd27ed6-44f9-486d-abaf-a'
b'779781431a0","id":"3dd27ed6-44f9-486d-abaf-a779781431a0"},{"memorySize":"NA","family":"Switches and Hubs","type":"Cisco Catalyst'
b' 9300 Switch","macAddress":"50:61:bf:ec:07:80","softwareType":"IOS-XE","softwareVersion":"16.6.4a","deviceSupportLevel":"Support'
b'ed","platformId":"C9300-48U","reachabilityFailureReason":"","series":"Cisco Catalyst 9300 Series Switches","serialNumber":"FCW22'
b'14L0UZ","inventoryStatusDetail":"<status><general code=\\"SUCCESS\\"/></status>","hostname":"leaf2.abc.inc","lastUpdateTime":15965'
b'20361668,"errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 05:52:41","lineCardCount":"0","lineCardId":"","l'
b'ocationName":null,"managementIpAddress":"10.10.20.82","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":"","tagCo'
b'unt":"0","tunnelUdpPort":null,"waasDeviceMode":null,"apManagerInterfaceIp":"","associatedWlcIp":"","bootDateTime":"2020-02-27 15'
b':29:41","collectionStatus":"Managed","errorCode":null,"roleSource":"AUTO","upTime":"158 days, 14:23:56.82","location":null,"role'
b'":"ACCESS","collectionInterval":"Global Default","instanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid":"5bc5b967-3f83-419'
b'5-891c-788f3e9048f3","id":"5bc5b967-3f83-4195-891c-788f3e9048f3"},{"memorySize":"NA","family":"Switches and Hubs","type":"Cisco '
b'Catalyst38xx stack-able ethernet switch","macAddress":"70:01:b5:5d:1b:00","softwareType":"IOS-XE","softwareVersion":"16.3.5b","d'
b'eviceSupportLevel":"Supported","platformId":"WS-C3850-24P-L","reachabilityFailureReason":"","series":"Cisco Catalyst 3850 Series'
b' Ethernet Stackable Switch","serialNumber":"FCW2212D05S","inventoryStatusDetail":"<status><general code=\\"SUCCESS\\"/></status>",'
b'"hostname":"spine1.abc.inc","lastUpdateTime":1596520396265,"errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-0'
b'4 05:53:16","lineCardCount":"0","lineCardId":"","locationName":null,"managementIpAddress":"10.10.20.80","reachabilityStatus":"Re'
b'achable","snmpContact":"","snmpLocation":"","tagCount":"0","tunnelUdpPort":null,"waasDeviceMode":null,"apManagerInterfaceIp":"",'
b'"associatedWlcIp":"","bootDateTime":"2020-02-12 19:01:16","collectionStatus":"Managed","errorCode":null,"roleSource":"MANUAL","u'
b'pTime":"173 days, 10:52:33.63","location":null,"role":"UNKNOWN","collectionInterval":"Global Default","instanceTenantId":"5e5a43'
b'2575161200cc4ac95c","instanceUuid":"2f0b7d3b-c9e1-491e-a584-f272b5403719","id":"2f0b7d3b-c9e1-491e-a584-f272b5403719"},{"memoryS'
b'ize":"NA","family":"Unified AP","type":"Cisco 1140 Unified Access Point","macAddress":"00:2b:01:00:02:00","softwareType":null,"s'
b'oftwareVersion":"8.5.97.162","deviceSupportLevel":"Unsupported","platformId":"AIR-AP1141N-A-K9","reachabilityFailureReason":"NA"'
b',"series":"Cisco 1140 Series Unified Access Points","serialNumber":"1140K0001","inventoryStatusDetail":"NA","hostname":"T1-1","l'
b'astUpdateTime":1596501161400,"errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCount":"0'
b'","lineCardId":"","locationName":null,"managementIpAddress":"10.10.20.241","reachabilityStatus":"Reachable","snmpContact":"","sn'
b'mpLocation":"Global/HQ/Floor 17","tagCount":"0","tunnelUdpPort":"16666","waasDeviceMode":null,"apManagerInterfaceIp":"10.10.20.5'
b'1","associatedWlcIp":"10.10.20.51","bootDateTime":null,"collectionStatus":"Managed","errorCode":"null","roleSource":"AUTO","upTi'
b'me":"138days 03:10:21.330","location":null,"role":"ACCESS","collectionInterval":"NA","instanceTenantId":"5e5a432575161200cc4ac95'
b'c","instanceUuid":"8b5fb4b6-2c84-409f-9950-c2d12e06ed17","id":"8b5fb4b6-2c84-409f-9950-c2d12e06ed17"},{"memorySize":"NA","family'
b'":"Unified AP","type":"Cisco 1140 Unified Access Point","macAddress":"00:2b:01:00:0b:00","softwareType":null,"softwareVersion":"'
b'8.5.97.162","deviceSupportLevel":"Unsupported","platformId":"AIR-AP1141N-A-K9","reachabilityFailureReason":"NA","series":"Cisco '
b'1140 Series Unified Access Points","serialNumber":"1140K0010","inventoryStatusDetail":"NA","hostname":"T1-10","lastUpdateTime":1'
b'596501161400,"errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCount":"0","lineCardId":"'
b'","locationName":null,"managementIpAddress":"10.10.20.250","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":"def'
b'ault-location ","tagCount":"0","tunnelUdpPort":"16666","waasDeviceMode":null,"apManagerInterfaceIp":"10.10.20.51","associatedWlc'
b'Ip":"10.10.20.51","bootDateTime":null,"collectionStatus":"Managed","errorCode":"null","roleSource":"AUTO","upTime":"138days 03:0'
b'9:04.340","location":null,"role":"ACCESS","collectionInterval":"NA","instanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid"'
b':"fe55667c-6de4-4657-b68c-60f17b21d23b","id":"fe55667c-6de4-4657-b68c-60f17b21d23b"},{"memorySize":"NA","family":"Unified AP","t'
b'ype":"Cisco 1140 Unified Access Point","macAddress":"00:2b:01:00:03:00","softwareType":null,"softwareVersion":"8.5.97.162","devi'
b'ceSupportLevel":"Unsupported","platformId":"AIR-AP1141N-A-K9","reachabilityFailureReason":"NA","series":"Cisco 1140 Series Unifi'
b'ed Access Points","serialNumber":"1140K0002","inventoryStatusDetail":"NA","hostname":"T1-2","lastUpdateTime":1596501161400,"erro'
b'rDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCount":"0","lineCardId":"","locationName":n'
b'ull,"managementIpAddress":"10.10.20.242","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":"Global/HQ/Floor 17","'
b'tagCount":"0","tunnelUdpPort":"16666","waasDeviceMode":null,"apManagerInterfaceIp":"10.10.20.51","associatedWlcIp":"10.10.20.51"'
b',"bootDateTime":null,"collectionStatus":"Managed","errorCode":"null","roleSource":"AUTO","upTime":"138days 03:10:21.330","locati'
b'on":null,"role":"ACCESS","collectionInterval":"NA","instanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid":"d5069e6d-e5f5-4'
b'917-b522-1e5d93c66ea0","id":"d5069e6d-e5f5-4917-b522-1e5d93c66ea0"},{"memorySize":"NA","family":"Unified AP","type":"Cisco 1140 '
b'Unified Access Point","macAddress":"00:2b:01:00:04:00","softwareType":null,"softwareVersion":"8.5.97.162","deviceSupportLevel":"'
b'Unsupported","platformId":"AIR-AP1141N-A-K9","reachabilityFailureReason":"NA","series":"Cisco 1140 Series Unified Access Points"'
b',"serialNumber":"1140K0003","inventoryStatusDetail":"NA","hostname":"T1-3","lastUpdateTime":1596501161400,"errorDescription":nul'
b'l,"interfaceCount":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCount":"0","lineCardId":"","locationName":null,"managementIp'
b'Address":"10.10.20.243","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":"Global/HQ/Floor 17","tagCount":"0","tu'
b'nnelUdpPort":"16666","waasDeviceMode":null,"apManagerInterfaceIp":"10.10.20.51","associatedWlcIp":"10.10.20.51","bootDateTime":n'
b'ull,"collectionStatus":"Managed","errorCode":"null","roleSource":"AUTO","upTime":"138days 03:09:13.330","location":null,"role":"'
b'ACCESS","collectionInterval":"NA","instanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid":"da13b595-7ed9-4fc8-ba3a-d7b6cbff'
b'6dcc","id":"da13b595-7ed9-4fc8-ba3a-d7b6cbff6dcc"},{"memorySize":"NA","family":"Unified AP","type":"Cisco 1140 Unified Access Po'
b'int","macAddress":"00:2b:01:00:05:00","softwareType":null,"softwareVersion":"8.5.97.162","deviceSupportLevel":"Unsupported","pla'
b'tformId":"AIR-AP1141N-A-K9","reachabilityFailureReason":"NA","series":"Cisco 1140 Series Unified Access Points","serialNumber":"'
b'1140K0004","inventoryStatusDetail":"NA","hostname":"T1-4","lastUpdateTime":1596501161400,"errorDescription":null,"interfaceCount'
b'":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCount":"0","lineCardId":"","locationName":null,"managementIpAddress":"10.10.2'
b'0.244","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":"default-location ","tagCount":"0","tunnelUdpPort":"1666'
b'6","waasDeviceMode":null,"apManagerInterfaceIp":"10.10.20.51","associatedWlcIp":"10.10.20.51","bootDateTime":null,"collectionSta'
b'tus":"Managed","errorCode":"null","roleSource":"AUTO","upTime":"138days 03:05:05.330","location":null,"role":"ACCESS","collectio'
b'nInterval":"NA","instanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid":"f696638c-53fe-4b42-b6c1-a37d8892e736","id":"f69663'
b'8c-53fe-4b42-b6c1-a37d8892e736"},{"memorySize":"NA","family":"Unified AP","type":"Cisco 1140 Unified Access Point","macAddress":'
b'"00:2b:01:00:06:00","softwareType":null,"softwareVersion":"8.5.97.162","deviceSupportLevel":"Unsupported","platformId":"AIR-AP11'
b'41N-A-K9","reachabilityFailureReason":"NA","series":"Cisco 1140 Series Unified Access Points","serialNumber":"1140K0005","invent'
b'oryStatusDetail":"NA","hostname":"T1-5","lastUpdateTime":1596501161400,"errorDescription":null,"interfaceCount":"0","lastUpdated'
b'":"2020-08-04 00:32:41","lineCardCount":"0","lineCardId":"","locationName":null,"managementIpAddress":"10.10.20.245","reachabili'
b'tyStatus":"Reachable","snmpContact":"","snmpLocation":"default-location ","tagCount":"0","tunnelUdpPort":"16666","waasDeviceMode'
b'":null,"apManagerInterfaceIp":"10.10.20.51","associatedWlcIp":"10.10.20.51","bootDateTime":null,"collectionStatus":"Managed","er'
b'rorCode":"null","roleSource":"AUTO","upTime":"138days 03:05:05.340","location":null,"role":"ACCESS","collectionInterval":"NA","i'
b'nstanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid":"75d57d36-dade-40cb-aac3-b2267e7e0180","id":"75d57d36-dade-40cb-aac3-'
b'b2267e7e0180"},{"memorySize":"NA","family":"Unified AP","type":"Cisco 1140 Unified Access Point","macAddress":"00:2b:01:00:07:00'
b'","softwareType":null,"softwareVersion":"8.5.97.162","deviceSupportLevel":"Unsupported","platformId":"AIR-AP1141N-A-K9","reachab'
b'ilityFailureReason":"NA","series":"Cisco 1140 Series Unified Access Points","serialNumber":"1140K0006","inventoryStatusDetail":"'
b'NA","hostname":"T1-6","lastUpdateTime":1596501161400,"errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 00:3'
b'2:41","lineCardCount":"0","lineCardId":"","locationName":null,"managementIpAddress":"10.10.20.246","reachabilityStatus":"Reachab'
b'le","snmpContact":"","snmpLocation":"default-location ","tagCount":"0","tunnelUdpPort":"16666","waasDeviceMode":null,"apManagerI'
b'nterfaceIp":"10.10.20.51","associatedWlcIp":"10.10.20.51","bootDateTime":null,"collectionStatus":"Managed","errorCode":"null","r'
b'oleSource":"AUTO","upTime":"138days 03:09:03.340","location":null,"role":"ACCESS","collectionInterval":"NA","instanceTenantId":"'
b'5e5a432575161200cc4ac95c","instanceUuid":"39cc2101-1a68-455e-a2a7-49d1cfb31835","id":"39cc2101-1a68-455e-a2a7-49d1cfb31835"},{"m'
b'emorySize":"NA","family":"Unified AP","type":"Cisco 1140 Unified Access Point","macAddress":"00:2b:01:00:08:00","softwareType":n'
b'ull,"softwareVersion":"8.5.97.162","deviceSupportLevel":"Unsupported","platformId":"AIR-AP1141N-A-K9","reachabilityFailureReason'
b'":"NA","series":"Cisco 1140 Series Unified Access Points","serialNumber":"1140K0007","inventoryStatusDetail":"NA","hostname":"T1'
b'-7","lastUpdateTime":1596501161400,"errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCou'
b'nt":"0","lineCardId":"","locationName":null,"managementIpAddress":"10.10.20.247","reachabilityStatus":"Reachable","snmpContact":'
b'"","snmpLocation":"default-location ","tagCount":"0","tunnelUdpPort":"16666","waasDeviceMode":null,"apManagerInterfaceIp":"10.10'
b'.20.51","associatedWlcIp":"10.10.20.51","bootDateTime":null,"collectionStatus":"Managed","errorCode":"null","roleSource":"AUTO",'
b'"upTime":"138days 03:09:03.340","location":null,"role":"ACCESS","collectionInterval":"NA","instanceTenantId":"5e5a432575161200cc'
b'4ac95c","instanceUuid":"b2bf41bf-0e2f-4255-85ad-4ca403686b3a","id":"b2bf41bf-0e2f-4255-85ad-4ca403686b3a"},{"memorySize":"NA","f'
b'amily":"Unified AP","type":"Cisco 1140 Unified Access Point","macAddress":"00:2b:01:00:09:00","softwareType":null,"softwareVersi'
b'on":"8.5.97.162","deviceSupportLevel":"Unsupported","platformId":"AIR-AP1141N-A-K9","reachabilityFailureReason":"NA","series":"C'
b'isco 1140 Series Unified Access Points","serialNumber":"1140K0008","inventoryStatusDetail":"NA","hostname":"T1-8","lastUpdateTim'
b'e":1596501161400,"errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCount":"0","lineCardI'
b'd":"","locationName":null,"managementIpAddress":"10.10.20.248","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":'
b'"default-location ","tagCount":"0","tunnelUdpPort":"16666","waasDeviceMode":null,"apManagerInterfaceIp":"10.10.20.51","associate'
b'dWlcIp":"10.10.20.51","bootDateTime":null,"collectionStatus":"Managed","errorCode":"null","roleSource":"AUTO","upTime":"138days '
b'03:09:03.340","location":null,"role":"ACCESS","collectionInterval":"NA","instanceTenantId":"5e5a432575161200cc4ac95c","instanceU'
b'uid":"bafa2b45-b827-48d5-9022-8c66b5a5b18f","id":"bafa2b45-b827-48d5-9022-8c66b5a5b18f"},{"memorySize":"NA","family":"Unified AP'
b'","type":"Cisco 1140 Unified Access Point","macAddress":"00:2b:01:00:0a:00","softwareType":null,"softwareVersion":"8.5.97.162","'
b'deviceSupportLevel":"Unsupported","platformId":"AIR-AP1141N-A-K9","reachabilityFailureReason":"NA","series":"Cisco 1140 Series U'
b'nified Access Points","serialNumber":"1140K0009","inventoryStatusDetail":"NA","hostname":"T1-9","lastUpdateTime":1596501161400,"'
b'errorDescription":null,"interfaceCount":"0","lastUpdated":"2020-08-04 00:32:41","lineCardCount":"0","lineCardId":"","locationNam'
b'e":null,"managementIpAddress":"10.10.20.249","reachabilityStatus":"Reachable","snmpContact":"","snmpLocation":"default-location '
b'","tagCount":"0","tunnelUdpPort":"16666","waasDeviceMode":null,"apManagerInterfaceIp":"10.10.20.51","associatedWlcIp":"10.10.20.'
b'51","bootDateTime":null,"collectionStatus":"Managed","errorCode":"null","roleSource":"AUTO","upTime":"138days 03:09:03.340","loc'
b'ation":null,"role":"ACCESS","collectionInterval":"NA","instanceTenantId":"5e5a432575161200cc4ac95c","instanceUuid":"85daf2da-571'
b'a-4570-9ce3-c68867ad891a","id":"85daf2da-571a-4570-9ce3-c68867ad891a"}],"version":"1.0"}'

This doesn’t look very pretty does it? We see that DNA-C returned a 200 OK and that the class is requests.models.Response, meaning that it’s a response. We then iterated over the response and saw a lot of byte-encoded data. But the data isn’t structured so we want to convert it to JSON. Let’s add a couple more lines of Python and then look again:

get_resp_json = get_resp.json()
    print(type(get_resp_json))
    print(get_resp_json)

This gives the following output:

daniel@devasc:~/DevAsc/nrusso$ python3 test.py 
<class 'dict'>
{'response': [{'memorySize': '3735220224', 'family': 'Wireless Controller', 'type': 'Cisco 3504 Wireless LAN Controller', 'macAddress': '50:61:bf:57:2f:00', 'softwareType': 'Cisco Controller', 'softwareVersion': '8.8.111.0', 'deviceSupportLevel': 'Supported', 'platformId': 'AIR-CT3504-K9', 'reachabilityFailureReason': '', 'series': 'Cisco 3500 Series Wireless LAN Controller', 'serialNumber': 'FCW2218M0B1', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': '3504_WLC', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.51', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-03-12 16:06:41', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'AUTO', 'upTime': '144 days, 8:26:01.00', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '72dc1f0a-e4da-4ec3-a055-822416894dd5', 'id': '72dc1f0a-e4da-4ec3-a055-822416894dd5'}, {'memorySize': 'NA', 'family': 'Switches and Hubs', 'type': 'Cisco Catalyst 9300 Switch', 'macAddress': '00:72:78:54:d1:00', 'softwareType': 'IOS-XE', 'softwareVersion': '16.6.4a', 'deviceSupportLevel': 'Supported', 'platformId': 'C9300-48U', 'reachabilityFailureReason': '', 'series': 'Cisco Catalyst 9300 Series Switches', 'serialNumber': 'FCW2214L0VK', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': 'leaf1', 'lastUpdateTime': 1596520840066, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 06:00:40', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.81', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': None, 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-02-27 15:29:40', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'AUTO', 'upTime': '158 days, 14:31:12.43', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '3dd27ed6-44f9-486d-abaf-a779781431a0', 'id': '3dd27ed6-44f9-486d-abaf-a779781431a0'}, {'memorySize': 'NA', 'family': 'Switches and Hubs', 'type': 'Cisco Catalyst 9300 Switch', 'macAddress': '50:61:bf:ec:07:80', 'softwareType': 'IOS-XE', 'softwareVersion': '16.6.4a', 'deviceSupportLevel': 'Supported', 'platformId': 'C9300-48U', 'reachabilityFailureReason': '', 'series': 'Cisco Catalyst 9300 Series Switches', 'serialNumber': 'FCW2214L0UZ', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': 'leaf2.abc.inc', 'lastUpdateTime': 1596520971947, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 06:02:51', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.82', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': None, 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-02-27 15:28:51', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'AUTO', 'upTime': '158 days, 14:34:06.90', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '5bc5b967-3f83-4195-891c-788f3e9048f3', 'id': '5bc5b967-3f83-4195-891c-788f3e9048f3'}, {'memorySize': 'NA', 'family': 'Switches and Hubs', 'type': 'Cisco Catalyst38xx stack-able ethernet switch', 'macAddress': '70:01:b5:5d:1b:00', 'softwareType': 'IOS-XE', 'softwareVersion': '16.3.5b', 'deviceSupportLevel': 'Supported', 'platformId': 'WS-C3850-24P-L', 'reachabilityFailureReason': '', 'series': 'Cisco Catalyst 3850 Series Ethernet Stackable Switch', 'serialNumber': 'FCW2212D05S', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': 'spine1.abc.inc', 'lastUpdateTime': 1596521006169, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 06:03:26', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.80', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': None, 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-02-12 19:01:26', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'MANUAL', 'upTime': '173 days, 11:02:43.72', 'location': None, 'role': 'UNKNOWN', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '2f0b7d3b-c9e1-491e-a584-f272b5403719', 'id': '2f0b7d3b-c9e1-491e-a584-f272b5403719'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:02:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0001', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-1', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.241', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'Global/HQ/Floor 17', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:10:21.330', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '8b5fb4b6-2c84-409f-9950-c2d12e06ed17', 'id': '8b5fb4b6-2c84-409f-9950-c2d12e06ed17'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:0b:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0010', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-10', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.250', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:04.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'fe55667c-6de4-4657-b68c-60f17b21d23b', 'id': 'fe55667c-6de4-4657-b68c-60f17b21d23b'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:03:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0002', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-2', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.242', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'Global/HQ/Floor 17', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:10:21.330', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'd5069e6d-e5f5-4917-b522-1e5d93c66ea0', 'id': 'd5069e6d-e5f5-4917-b522-1e5d93c66ea0'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:04:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0003', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-3', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.243', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'Global/HQ/Floor 17', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:13.330', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'da13b595-7ed9-4fc8-ba3a-d7b6cbff6dcc', 'id': 'da13b595-7ed9-4fc8-ba3a-d7b6cbff6dcc'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:05:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0004', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-4', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.244', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:05:05.330', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'f696638c-53fe-4b42-b6c1-a37d8892e736', 'id': 'f696638c-53fe-4b42-b6c1-a37d8892e736'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:06:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0005', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-5', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.245', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:05:05.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '75d57d36-dade-40cb-aac3-b2267e7e0180', 'id': '75d57d36-dade-40cb-aac3-b2267e7e0180'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:07:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0006', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-6', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.246', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:03.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '39cc2101-1a68-455e-a2a7-49d1cfb31835', 'id': '39cc2101-1a68-455e-a2a7-49d1cfb31835'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:08:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0007', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-7', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.247', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:03.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'b2bf41bf-0e2f-4255-85ad-4ca403686b3a', 'id': 'b2bf41bf-0e2f-4255-85ad-4ca403686b3a'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:09:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0008', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-8', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.248', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:03.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'bafa2b45-b827-48d5-9022-8c66b5a5b18f', 'id': 'bafa2b45-b827-48d5-9022-8c66b5a5b18f'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:0a:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0009', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-9', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.249', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:03.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '85daf2da-571a-4570-9ce3-c68867ad891a', 'id': '85daf2da-571a-4570-9ce3-c68867ad891a'}], 'version': '1.0'}

Running .json() in requests, gave us back a dictionary. There are two keys, response and version. The value for response is a list of dictionaries. To access the key response, reference it within brackets:

print(get_resp_json["response"])
    print(type(get_resp_json["response"]))

This provides the following output:

daniel@devasc:~/DevAsc/nrusso$ python3 test.py 
[{'memorySize': '3735220224', 'family': 'Wireless Controller', 'type': 'Cisco 3504 Wireless LAN Controller', 'macAddress': '50:61:bf:57:2f:00', 'softwareType': 'Cisco Controller', 'softwareVersion': '8.8.111.0', 'deviceSupportLevel': 'Supported', 'platformId': 'AIR-CT3504-K9', 'reachabilityFailureReason': '', 'series': 'Cisco 3500 Series Wireless LAN Controller', 'serialNumber': 'FCW2218M0B1', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': '3504_WLC', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.51', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-03-12 16:06:41', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'AUTO', 'upTime': '144 days, 8:26:01.00', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '72dc1f0a-e4da-4ec3-a055-822416894dd5', 'id': '72dc1f0a-e4da-4ec3-a055-822416894dd5'}, {'memorySize': 'NA', 'family': 'Switches and Hubs', 'type': 'Cisco Catalyst 9300 Switch', 'macAddress': '00:72:78:54:d1:00', 'softwareType': 'IOS-XE', 'softwareVersion': '16.6.4a', 'deviceSupportLevel': 'Supported', 'platformId': 'C9300-48U', 'reachabilityFailureReason': '', 'series': 'Cisco Catalyst 9300 Series Switches', 'serialNumber': 'FCW2214L0VK', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': 'leaf1', 'lastUpdateTime': 1596522060483, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 06:21:00', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.81', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': None, 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-02-27 15:30:00', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'AUTO', 'upTime': '158 days, 14:51:32.65', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '3dd27ed6-44f9-486d-abaf-a779781431a0', 'id': '3dd27ed6-44f9-486d-abaf-a779781431a0'}, {'memorySize': 'NA', 'family': 'Switches and Hubs', 'type': 'Cisco Catalyst 9300 Switch', 'macAddress': '50:61:bf:ec:07:80', 'softwareType': 'IOS-XE', 'softwareVersion': '16.6.4a', 'deviceSupportLevel': 'Supported', 'platformId': 'C9300-48U', 'reachabilityFailureReason': '', 'series': 'Cisco Catalyst 9300 Series Switches', 'serialNumber': 'FCW2214L0UZ', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': 'leaf2.abc.inc', 'lastUpdateTime': 1596522191572, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 06:23:11', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.82', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': None, 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-02-27 15:29:11', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'AUTO', 'upTime': '158 days, 14:54:27.22', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '5bc5b967-3f83-4195-891c-788f3e9048f3', 'id': '5bc5b967-3f83-4195-891c-788f3e9048f3'}, {'memorySize': 'NA', 'family': 'Switches and Hubs', 'type': 'Cisco Catalyst38xx stack-able ethernet switch', 'macAddress': '70:01:b5:5d:1b:00', 'softwareType': 'IOS-XE', 'softwareVersion': '16.3.5b', 'deviceSupportLevel': 'Supported', 'platformId': 'WS-C3850-24P-L', 'reachabilityFailureReason': '', 'series': 'Cisco Catalyst 3850 Series Ethernet Stackable Switch', 'serialNumber': 'FCW2212D05S', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': 'spine1.abc.inc', 'lastUpdateTime': 1596522226792, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 06:23:46', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.80', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': None, 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-02-12 19:00:46', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'MANUAL', 'upTime': '173 days, 11:23:03.96', 'location': None, 'role': 'UNKNOWN', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '2f0b7d3b-c9e1-491e-a584-f272b5403719', 'id': '2f0b7d3b-c9e1-491e-a584-f272b5403719'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:02:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0001', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-1', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.241', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'Global/HQ/Floor 17', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:10:21.330', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '8b5fb4b6-2c84-409f-9950-c2d12e06ed17', 'id': '8b5fb4b6-2c84-409f-9950-c2d12e06ed17'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:0b:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0010', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-10', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.250', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:04.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'fe55667c-6de4-4657-b68c-60f17b21d23b', 'id': 'fe55667c-6de4-4657-b68c-60f17b21d23b'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:03:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0002', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-2', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.242', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'Global/HQ/Floor 17', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:10:21.330', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'd5069e6d-e5f5-4917-b522-1e5d93c66ea0', 'id': 'd5069e6d-e5f5-4917-b522-1e5d93c66ea0'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:04:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0003', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-3', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.243', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'Global/HQ/Floor 17', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:13.330', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'da13b595-7ed9-4fc8-ba3a-d7b6cbff6dcc', 'id': 'da13b595-7ed9-4fc8-ba3a-d7b6cbff6dcc'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:05:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0004', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-4', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.244', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:05:05.330', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'f696638c-53fe-4b42-b6c1-a37d8892e736', 'id': 'f696638c-53fe-4b42-b6c1-a37d8892e736'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:06:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0005', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-5', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.245', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:05:05.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '75d57d36-dade-40cb-aac3-b2267e7e0180', 'id': '75d57d36-dade-40cb-aac3-b2267e7e0180'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:07:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0006', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-6', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.246', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:03.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '39cc2101-1a68-455e-a2a7-49d1cfb31835', 'id': '39cc2101-1a68-455e-a2a7-49d1cfb31835'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:08:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0007', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-7', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.247', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:03.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'b2bf41bf-0e2f-4255-85ad-4ca403686b3a', 'id': 'b2bf41bf-0e2f-4255-85ad-4ca403686b3a'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:09:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0008', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-8', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.248', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:03.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': 'bafa2b45-b827-48d5-9022-8c66b5a5b18f', 'id': 'bafa2b45-b827-48d5-9022-8c66b5a5b18f'}, {'memorySize': 'NA', 'family': 'Unified AP', 'type': 'Cisco 1140 Unified Access Point', 'macAddress': '00:2b:01:00:0a:00', 'softwareType': None, 'softwareVersion': '8.5.97.162', 'deviceSupportLevel': 'Unsupported', 'platformId': 'AIR-AP1141N-A-K9', 'reachabilityFailureReason': 'NA', 'series': 'Cisco 1140 Series Unified Access Points', 'serialNumber': '1140K0009', 'inventoryStatusDetail': 'NA', 'hostname': 'T1-9', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.249', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': 'default-location ', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '10.10.20.51', 'associatedWlcIp': '10.10.20.51', 'bootDateTime': None, 'collectionStatus': 'Managed', 'errorCode': 'null', 'roleSource': 'AUTO', 'upTime': '138days 03:09:03.340', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'NA', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '85daf2da-571a-4570-9ce3-c68867ad891a', 'id': '85daf2da-571a-4570-9ce3-c68867ad891a'}]
<class 'list'>

Notice that this is a list. To access only the first element in the list, slicing can be used:

print(get_resp_json["response"][0])
    print(type(get_resp_json["response"][0]))

This gives the following output:

daniel@devasc:~/DevAsc/nrusso$ python3 test.py 
{'memorySize': '3735220224', 'family': 'Wireless Controller', 'type': 'Cisco 3504 Wireless LAN Controller', 'macAddress': '50:61:bf:57:2f:00', 'softwareType': 'Cisco Controller', 'softwareVersion': '8.8.111.0', 'deviceSupportLevel': 'Supported', 'platformId': 'AIR-CT3504-K9', 'reachabilityFailureReason': '', 'series': 'Cisco 3500 Series Wireless LAN Controller', 'serialNumber': 'FCW2218M0B1', 'inventoryStatusDetail': '<status><general code="SUCCESS"/></status>', 'hostname': '3504_WLC', 'lastUpdateTime': 1596501161400, 'errorDescription': None, 'interfaceCount': '0', 'lastUpdated': '2020-08-04 00:32:41', 'lineCardCount': '0', 'lineCardId': '', 'locationName': None, 'managementIpAddress': '10.10.20.51', 'reachabilityStatus': 'Reachable', 'snmpContact': '', 'snmpLocation': '', 'tagCount': '0', 'tunnelUdpPort': '16666', 'waasDeviceMode': None, 'apManagerInterfaceIp': '', 'associatedWlcIp': '', 'bootDateTime': '2020-03-12 16:06:41', 'collectionStatus': 'Managed', 'errorCode': None, 'roleSource': 'AUTO', 'upTime': '144 days, 8:26:01.00', 'location': None, 'role': 'ACCESS', 'collectionInterval': 'Global Default', 'instanceTenantId': '5e5a432575161200cc4ac95c', 'instanceUuid': '72dc1f0a-e4da-4ec3-a055-822416894dd5', 'id': '72dc1f0a-e4da-4ec3-a055-822416894dd5'}
<class 'dict'>

Notice that this is a dictionary and that we returned the first dictionary from the list.

Now, let’s go back to Nick’s code and explain what is going on:

if get_resp.ok:
        for device in get_resp.json()["response"]:
            print(f"ID: {device['id']}  IP: {device['managementIpAddress']}")

The first line checks that get_resp is ok, meaning that the status code is not in the 400 range. The next line iterates (loops) over the JSON version of the response from DNA-C. The key response is accessed, which if you remember, the value of response consists of a list of dictionaries. The code is going through each list entry, which is actually a dictionary. Finally, the ID and management IP of the device is printed. The variable device is used to reference each dictionary. Note that id and managementIpAddress are keys in this dictionary.

This is all a lot to take in! Which is why I wrote the post! So let’s break down and summarize what we learned:

  • The Python requests library was used to call the DNA-C API
  • A response was provided, which was byte-encoded by default
  • The response was converted to JSON format
    • This was an object consisting of an array of objects
    • A dictionary consisting of a list of dictionaries in Python speak
    • The keys are response and version
  • By accessing the key response, the value of this key is a list of dictionaries
    • This list is iterated over with a for loop
    • Hence accessing each dictionary, each device has a dictionary
    • Accessing the keys id and managementIpAddress

I hope you enjoyed this deep dive into understanding how to work with a list of dictionaries. If you want to learn more about requestshow Python loops really work, or working with lists and dictionaries, just click the links. I also recommend you get Postman to play around with APIs.

DevAsc – List Consisting of Dictonaries
Tagged on:                 

Leave a Reply

Your email address will not be published. Required fields are marked *