netmiko:send_config_from_file:显示设备证书时执行中断

问题描述

描述:我在多个设备中创建了用于命令自动化的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

开关#

请帮忙

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)