描述:我在 python 代码下面创建了多个设备中的命令自动化,但我面临的问题是代码在设备证书处自动停止
代码 :
from netmiko import ConnectHandler
import xlrd
loc= (r"E:\py\pyData1.xls")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
for i in range(sheet.nrows):
if i == 0:
continue
else:
row = sheet.row_slice(i)
if row[0].value == "":
break
else:
try:
cisco_881 = {
'device_type': row[0].value,
'ip': row[1].value,
'username': row[2].value,
'password': row[3].value,
# Multiple all of the delays by a factor of two
"global_delay_factor": 4
}
cfg_file = "commands.txt"
with ConnectHandler(**cisco_881) as net_connect:
output = net_connect.send_config_from_file(cfg_file) + "\n\n"
#---------------enable below command for automatically writing memory
#output += net_connect.save_config()
print()
print(output)
print()
fileName = row[1].value+".txt"
f = open(fileName, "w+")
f.write(output)
f.close()
except Exception as inst:
Output = "Type :" + type(inst) + " \n\n Arguments" +inst.args + "\n\n Expection: " +inst
print(type(inst)) # the exception instance
print(inst.args) # arguments stored in .args
print(inst) # __str__ allows args to be printed directly,
# but may be overridden in exception subclasses
FileName = row[1].value + "_Error.txt"
f = open(FileName, "w+")
f.write(Output)
f.close()
continue
命令文件数据
do show run
错误代码在批处理上正确执行,但在少数设备中,它会自动附加结尾并停止执行,尤其是在证书的情况下
2B8AB394 DA23AEEF 2B49BC4A D32B745B D2F2C6F7 64BF60EB 6F32086C D31A48FE 1B072237 256B80BC 32DE587D 73end
转变#
请帮助