Python Netmiko timesout(尽管延迟系数=4)-操作错误:在发送命令中从未检测到搜索模式
这是我大得多的程序的一部分,但我已将错误隔离到这个简短的示例中: 我正在Cisco IOS XE设备上运行ping命令,ping需要一段时间才能完成。因此,为了避免不必要的超时,我为Python Netmiko timesout(尽管延迟系数=4)-操作错误:在发送命令中从未检测到搜索模式,python,netmiko,oserror,Python,Netmiko,Oserror,这是我大得多的程序的一部分,但我已将错误隔离到这个简短的示例中: 我正在Cisco IOS XE设备上运行ping命令,ping需要一段时间才能完成。因此,为了避免不必要的超时,我为netmiko.ConnectHandler.send\u command() 但是,我仍然得到错误: [somsinha@cisco-cms.com@unlv1lnxjmpa01 pack_tests]$ time ./wo_thread.py Running Command: ping 1.1.1.1 so l
netmiko.ConnectHandler.send\u command()
但是,我仍然得到错误:
[somsinha@cisco-cms.com@unlv1lnxjmpa01 pack_tests]$ time ./wo_thread.py
Running Command: ping 1.1.1.1 so lo0 r 350 si 1400 df on R1
Traceback (most recent call last):
File "./wo_thread.py", line 52, in <module>
exec_cmd(v, 'ping 1.1.1.1 so lo0 r 350 si 1400 df')
File "./wo_thread.py", line 30, in exec_cmd
res += net_connect.send_command(cmd, delay_factor=5)
File "/home/somsinha@cisco-cms.com/pyScripts/dev/devEnv/lib/python3.7/site-packages/netmiko/utilities.py", line 363, in wrapper_decorator
return func(self, *args, **kwargs)
File "/home/somsinha@cisco-cms.com/pyScripts/dev/devEnv/lib/python3.7/site-packages/netmiko/base_connection.py", line 1488, in send_command
search_pattern
OSError: Search pattern never detected in send_command_expect: R1#
real 0m23.647s
user 0m0.582s
sys 0m0.127s
正如您在上面所看到的,开始和结束时间的实际差异是~24秒
——因此没有理由不起作用。知道怎么回事吗,伙计们
我的代码是:
#!/usr/bin/python3
import os, sys
from netmiko import ConnectHandler
from pprint import pprint
from datetime import datetime, timedelta
dev = {
"device_type": "cisco_xe",
"host": '9.9.9.9',
"username": 'user',
"password": 'pass',
}
def exec_cmd(out, cmd):
with ConnectHandler(**dev) as net_connect:
if type(cmd) != list:
d_name = net_connect.find_prompt()
res = d_name + cmd + '\n'
print(f"Running Command: {cmd} on {d_name.replace('#', '')}", end='', flush=True)
res += net_connect.send_command(cmd, delay_factor=5)
out.append(res)
print('\x1b[2K\r', end = '') # Clear the old 'Running ...' Line
print(f"Obtained result for {cmd}")
else:
out_lst = []
for c in cmd:
exec_cmd(out_lst, c)
out.append(out_lst)
v = []
exec_cmd(v, 'ping 130.24.4.4 so lo0 r 350 si 1400 df')
print(v)
exit(1)
这可能是一个bug 见: 修正: 在设备配置中添加
“fast\u cli”:False
。完整代码:
dev = {
"device_type": "cisco_xe",
"host": '9.9.9.9',
"username": 'user',
"password": 'pass',
"fast_cli": False,
}
dev = {
"device_type": "cisco_xe",
"host": '9.9.9.9',
"username": 'user',
"password": 'pass',
"fast_cli": False,
}