我想将Python库ncclient 0.6.6与Python 2.7.15一起使用以连接到NETCONF服务器(netopeer2)并读出正在运行的配置。
我尝试按照手册中的示例在控制台中运行以下代码:
with manager.connect(host="*the IP adress*", port=*the port*, timeout=None, username="*user*", password="*pwd*") as m:
c = m.get_config(source='running').data_xml
with open("%s.xml" % host, 'w') as f:
f.write(c)
如手册中所述,我尝试使用allow_agent和look_for_keys设置为False禁用公钥身份验证。不幸的是,这不能正常工作,因为我收到了错误消息:
File "<stdin>", line 1, in <module>
File "/home/sisc/.local/lib/python2.7/site-packages/ncclient/manager.py", line 177, in connect
return connect_ssh(*args, **kwds)
File "/home/sisc/.local/lib/python2.7/site-packages/ncclient/manager.py", line 143, in connect_ssh
session.connect(*args, **kwds)
File "/home/sisc/.local/lib/python2.7/site-packages/ncclient/transport/ssh.py", line 481, in connect
raise SSHUnknownHostError(known_hosts_lookup, fingerprint)
ncclient.transport.errors.SSHUnknownHostError: Unknown host key [e3:8d:35:a9:43:f9:3c:8a:f4:d3:88:5b:a9:36:93:59] for [[192.168.56.2]:1831]
我不明白为什么它仍然抱怨未知的主机密钥,即使我明确禁用了公共(public)密钥身份验证也是如此。
netopeer NETCONF服务器肯定正在运行,因为一旦我尝试从终端通过SSH进入它,我就会收到“Hello”消息。
我错过了什么?
最佳答案
m = manager.connect(host="172.17.0.2", port=830, username="netconf", password="netconf", hostkey_verify=False)
做到了。 Hostkey_verify必须为false。
关于ssh - ncclient:连接到NETCONF服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56634650/