我正在使用高级 python 库ncclient来编辑 NETCONF 设备的配置,但我遇到了这个错误:
ValueError: Invalid attribute name u'xmlns:if'
我怀疑这与 xml 命名空间问题有关,因为 lxml 库抱怨属性名称
我正在做的就是创建与设备的连接然后关闭它
manager = ncclient.manager.connect(
host=host,
port=port,
username=username,
password=b64decode(password),
device_params={
"name": "nexus",
"ssh_subsystem_name": "xmlagent"
}
)
manager.close_session()
这是一个堆栈跟踪:
Traceback (most recent call last):
File "./switch_config.py", line 41, in <module>
main()
File "./switch_config.py", line 26, in main
manager.close_session()
File "/usr/lib/python2.6/site-packages/ncclient/manager.py", line 107, in wrapper
return self.execute(op_cls, *args, **kwds)
File "/usr/lib/python2.6/site-packages/ncclient/manager.py", line 174, in execute
raise_mode=self._raise_mode).request(*args, **kwds)
File "/usr/lib/python2.6/site-packages/ncclient/operations/session.py", line 28, in request
return self._request(new_ele("close-session"))
File "/usr/lib/python2.6/site-packages/ncclient/operations/rpc.py", line 290, in _request
req = self._wrap(op)
File "/usr/lib/python2.6/site-packages/ncclient/operations/rpc.py", line 275, in _wrap
**self._device_handler.get_xml_extra_prefix_kwargs())
File "/usr/lib/python2.6/site-packages/ncclient/xml_.py", line 153, in <lambda>
new_ele = lambda tag, attrs={}, **extra: etree.Element(qualify(tag), attrs, **extra)
File "lxml.etree.pyx", line 2812, in lxml.etree.Element (src/lxml/lxml.etree.c:61433)
File "apihelpers.pxi", line 123, in lxml.etree._makeElement (src/lxml/lxml.etree.c:13864)
File "apihelpers.pxi", line 111, in lxml.etree._makeElement (src/lxml/lxml.etree.c:13736)
File "apihelpers.pxi", line 263, in lxml.etree._initNodeAttributes (src/lxml/lxml.etree.c:15391)
File "apihelpers.pxi", line 1524, in lxml.etree._attributeValidOrRaise (src/lxml/lxml.etree.c:26886)
ValueError: Invalid attribute name u'xmlns:if'