1

我想使用 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]

我不明白为什么它仍然抱怨未知的主机密钥,即使我明确禁用了公钥身份验证。netopeer NETCONF 服务器肯定正在运行,因为一旦我尝试从终端通过 SSH 连接到它,我就会收到一条“Hello”消息。我错过了什么?

4

1 回答 1

2
m = manager.connect(host="172.17.0.2", port=830, username="netconf", password="netconf", hostkey_verify=False)

成功了。Hostkey_verify 必须为假。

于 2019-06-24T14:09:45.453 回答