ncclient:连接到 NETCONF 服务器

ncclient: connecting to a NETCONF server

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

如手册中所写,我尝试禁用 public-密钥身份验证,将 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-key 身份验证。 netopeer NETCONF 服务器肯定是 运行,因为当我尝试从终端通过 SSH 进入它时,我会收到一条 "Hello" 消息。 我错过了什么吗?

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

成功了。 Hostkey_verify 必须为假。