首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >遇到NETCONF python库的xml无效属性名称

遇到NETCONF python库的xml无效属性名称
EN

Stack Overflow用户
提问于 2014-06-30 23:23:13
回答 1查看 1.3K关注 0票数 1

我正在使用一个高级python库ncclient来编辑NETCONF设备的配置,但是我遇到了这个错误:

代码语言:javascript
复制
ValueError: Invalid attribute name u'xmlns:if'

我怀疑这与xml名称空间问题有关,因为lxml库正在抱怨属性名称

我所要做的就是创建一个到设备的连接,然后关闭它

代码语言:javascript
复制
manager = ncclient.manager.connect(
    host=host,
    port=port,
    username=username,
    password=b64decode(password),
    device_params={
        "name": "nexus",
        "ssh_subsystem_name": "xmlagent"
    }
)
manager.close_session()

下面是堆栈跟踪:

代码语言:javascript
复制
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'
EN

回答 1

Stack Overflow用户

发布于 2014-09-18 10:32:56

我最终通过以下方式让它在NX-OS上运行:

删除ncclient/device/nexus.py中的所有名称空间,并添加名称空间"xmlns":"http://www.cisco.com/nxos:1.0:netconf"

代码语言:javascript
复制
def get_xml_base_namespace_dict(self):
    return { "xmlns":"http://www.cisco.com/nxos:1.0:netconf" }      #Add root namespace

def get_xml_extra_prefix_kwargs(self):
    d = {
            # "xmlns:nxos":"http://www.cisco.com/nxos:1.0",           #remove other namespaces
            # "xmlns:if":"http://www.cisco.com/nxos:1.0:if_manager"
        }
    d.update(self.get_xml_base_namespace_dict())
    return d
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24493584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档