On 06/12/2018 14:17, Ravi Kumar wrote: > 1)The for loops that have written I am able to access all the networks,able > to loop through all access points(Devices) in the network,able to loop > through and get all clients in each access points but when it comea to > client log events I am able to loop through and get only the last row of > accesspoints list and get those particular and clients and its log events
I don't know the cause, but did take a quick look at the code. One thing that makes it very difficult to follow is that you use the same variable names over and over making it hard to keep track of what any given 'item' or 'json_string' or 'r' actually holds at any given time. Buy using a different name for each json_string reflecting the expected data - such as json_networks or json_clients - it would be very much easier to follow the flow of the code. > I assume I am going wrong in the last for loop code and output as shown > below Probably but I confess I couldn't spot it from a casual read through. > for client in json_string: > > hostname = client.get("dhcpHostname") > description = client.get("description") > ipaddress = client.get("ip") > macaddress = client.get("mac") > > usage = client.get("usage") > sentbytes = usage.get("sent") > recvbytes = usage.get("recv") > > print ('{0:20} {1:20} {2:20} {3:30} {4:20} > {5:20}'.format(hostname, description, ipaddress, macaddress,sentbytes, > recvbytes)) > > > > for item in serialnumlist: > print ("\nQuerying Meraki for clientlogevents on Devices: (" + > item.get("mac") + ")") > > for item in json_string: > config_url = "/networks/"+"/N_63***1050/"+"/clients/"+ item.get("mac") > + "/events?perPage=1000" > r = requests.get(base_url + config_url, headers=headers) > > print ('{} '.format(r.content)) > **********************************> The 'item's in the last loop appear to be the same as the 'client's in the previous loop? Since 'json_string' never changes... Also the setialnumlist only prints the result it never stores anything. Then the last loop uses item.get(mac) which will not be the one printed earlier since item is now read from json_string(back tome earlier confusion over names!) I suspect this lack of continuity may be the root of your problem but the name collisions are twisting my brain and its late at night... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor