I am using python 3.8.5 to get data from an Infoblox appliance to determine the number of new entries for a given client name. In the example I've posted the client is ykk. I send the following search string:
All I need from the return is the hostname and the IP address. I may get a single DNS record in return or I may get multiple records. So I try and loop through the dictionary using this code:
resarr = []len1 = (out.keys())len2 = len(out['result'][0]['ipv4addrs'][0]['host'])try: for i in range(0, len2): drec = (out['result'][i]['ipv4addrs'][0]['host'], out['result'][i]['ipv4addrs'][0]['ipv4addr'] ) resarr.append(drec)except IndexError: print('uh oh')
My len1 and len2 don't provide useful values, certainly not the correct return value for what I need, and len2 is always larger than actual number of DNS entries returned so I can simply let it throw an IndexError and get all the data I need.
So I have 2 issues that are eluding me. First, I have tried several different variations on the len() function to see how many records are returned. I suspect this doesn't work because I am getting a nested dictionary back. Second, it seems like poor code to just let it throw an IndexError to stop the for loop.
I'm not sure what to try next. Any guidance would be appreciated.
Thanks again!
Steve