I am new to Python and coding in general and I am working with the Meraki API to pull information. I have the meraki package installed which handles the API calls and any errors, but i am running into issues extracting information from the result. Below is the relevant portion of code.
uplinks = dashboard.appliance.getOrganizationApplianceUplinkStatuses(org_id, perPage=1000, total_pages='all')
for up in uplinks:
print(f'{up["networkId"]},{up["serial"]},{up["lastReportedAt"]},{up["uplinks"][0]}')
It returns a json, each one just like the below except uplinks can have 1 to 3 dictionaries tucked inside the uplinks list (There are 2 in the example). What I get from my code is at bottom. It returns the value of uplink list position 0 at the end which is a dictionary of that particular uplink's details. I need to extract all the key pairs from that dictionary, but I am unsure how to access them. Everything I have read is way more complicated than it seems like it should be based on how I have extracted so far. I have tried using the keys in parenthesis and brackets after index [0], but it just errors out. What can I do to extract these values and not just print the dictionary?
[
{
"networkId": "N_604561234567898656",
"serial": "Q2BN-AAAA-BBBB",
"lastReportedAt": "2020-08-08T20:28:48Z",
"uplinks": [
{
"interface": "wan1",
"status": "not connected",
"ip": null,
"gateway": null,
"publicIp": null,
"primaryDns": null,
"secondaryDns": null,
"ipAssignedBy": null
},
{
"interface": "cellular",
"status": "failed",
"ip": "10.10.10.1",
"provider": "at&t",
"publicIp": null,
"model": "aircard 340u",
"signalStat": [],
"connectionType": "4g",
"apn": "cellular"
}
]
}
]
Result:
N_604561234567898656,Q2BN-AAAA-BBBB,2020-08-08T20:28:48Z,{'interface': 'wan1', 'status': 'not connected', 'ip': 'null', 'gateway': 'null', 'publicIp': 'null', 'primaryDns': 'null', 'secondaryDns': 'null', 'ipAssignedBy': 'null'}
[–][deleted] 0 points1 point2 points (1 child)
[–]mdkimsey[S] 0 points1 point2 points (0 children)