Output1 Error due Python ValueError: I/O operation on closed file
Output1 Error due Python ValueError: I/O operation on closed file
I have been trying to obtain data from a few cli commands into a server platform (splunk) which at this moment is working fine, however after a few minutes I can see this error:
**print(output1)
ValueError: I/O operation on closed file.**
Below is my code, keep in mind the imports and the file names are properly configured; I just want to know how can I fix this error on my code:
for host in ip_add_file:
host = host.strip()
device = ConnectHandler(device_type=platform, ip=host, username=username, password=password)
output = device.send_command('terminal length 0')
output = device.send_command('enable') #Editable to be what ever is needed
output1 = device.send_command('sh run | inc hostname', max_loops= 150, delay_factor=1)
output1 = output1.split(' ')
output1 = output1[1]
print(output1)
output2 = device.send_command('sh run | inc mwifi', max_loops= 150, delay_factor=1)
print(output2)
output3 = device.send_command('sh wireless wlan summary | inc mwifi', max_loops= 150, delay_factor=1)
print(output3)
my_dictionary= 'mydevice': host, 'hostname' : output1, 'cli_mwifi' : output2, 'output_mwifi' : output3
log.info('mwifi_data', extra = my_dictionary )
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.