cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
637
Views
0
Helpful
0
Replies

Key Errors when trying to create .csv with Genie with some keys

Richard G.
Level 1
Level 1

I just downloaded virl, pyATS, genie and am using a Devnet sandbox-

I am trying to create a simple cvs file using genie --"show interfaces"

The Dictionary was created but when i try and iterate through it, I get errors when testing some keys like "mac_address"

Other keys work fine-like, "delay", "line_protocol", 

 

I don't believe its the way the code is written since using some keys work, but am wondering if it is they

way genie is formatting.  Attached is the dictionary created by genie to show syntax and spacing

All needed modules/libraries were imported

 

 

code:

 

interfaces = ios_1.parse("show interfaces")
interface_file = "interfaces.csv"
report_fields = ["Column1", "Column2"]

with open("interface_file", "w") as f:

 

Working loop

 

with open(interface_file, "w") as f:
...: writer = csv.DictWriter(f, report_fields)
...: writer.writeheader()
...: for interface, details in interfaces.items():
...: writer.writerow(
...: {"Column1": interface,
...: "Column2": details["line_protocol"]})

In [112]:

 

Non Working:

with open(interface_file, "w") as f:
...: writer = csv.DictWriter(f, report_fields)
...: writer.writeheader()
...: for interface, details in interfaces.items():
...: writer.writerow(
...: {"Column1": interface,
...: "Column2": details["mac_address"]}

)

---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-112-b9b85ff68358> in <module>
5 writer.writerow(
6 {"Column1": interface,
----> 7 "Column2": details["mac_address"]}

)
8
9

KeyError: 'mac_address'

0 Replies 0