使用python中的Netmiko库通过SSH proxycommand自动执行Cisco登录,在执行脚本时会返回ssh协议标题问题, 一周以来一直在尝试找出此问题,但到目前为止还没有运气。 目标主机:Linux Netmiko版本:2.3.3 paramiko:2.5.0
host jump
hostname 172.16.1.10
IdentitiesOnly yes
host 192.168.1.10
ProxyCommand ssh jump nc %h %p
#!/usr/bin/env python
from netmiko import ConnectHandler
import paramiko
device = {
'device_type': 'linux',
'host': '192.168.1.10',
'username': 'testuser',
'password': 'Password',
'ssh_config_file': '~/.ssh/config',
}
net_connect = ConnectHandler(**device)
output1 = net_connect.send_command('uname -a')
print output1
No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last):
File "Python_Scripts/connection.py", line 12, in <module>
net_connect = ConnectHandler(**device)
File "/usr/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py", line 228, in ConnectHandler
return ConnectionClass(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 312, in __init__
self.establish_connection()
File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 858, in establish_connection
self.remote_conn_pre.connect(**ssh_connect_params)
File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 397, in connect
t.start_client(timeout=timeout)
File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 601, in start_client
raise e
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
答案 0 :(得分:0)
我认为这可能与以下问题有关:
https://github.com/ktbyers/netmiko/issues/1259
如果您的设备由于某种原因非常缓慢并且在合理的时间内没有响应(通过响应,我的意思是出示SSH标语),则Paramiko将引发错误。
我们可能会很快加入Paramiko的banner_timeout参数,以便您可以在Netmiko中增加此超时时间。