TypeError:类型“ NoneType”无法序列化

时间:2019-04-07 02:50:53

标签: ietf-netconf

我正在尝试使用netconfncclient获取路由器的运行配置。我的代码-

    #!/usr/bin/env python3.5

        try:
            from ncclient import manager

        host = '198.51.100.3'
        with manager.connect(host=host, port=22, username='lab9',password='lab9',hostkey_verify=False, device_params={'name':'iosxr'}) as m:
            c = m.get_config(source='running').data_xml
            #print (c.server_capabilities)
            with open(r1.xml, 'w') as f:
                f.write(c)

    except ImportError as e:
        print ("\n!!! ImportError !!!")
        print ("{0}. Install it.\n".format(e)) 

获取TypeError-

Traceback (most recent call last):
  File "ojb2.py", line 16, in <module>
    c = m.get_config(source='running').data_xml
  File "/usr/local/lib/python3.5/dist-packages/ncclient/operations/retrieve.py", line 64, in data_xml
    return to_xml(self._data)
  File "/usr/local/lib/python3.5/dist-packages/ncclient/xml_.py", line 100, in to_xml
    xml = etree.tostring(ele, encoding=encoding, pretty_print=pretty_print)
  File "src/lxml/lxml.etree.pyx", line 3350, in lxml.etree.tostring (src/lxml/lxml.etree.c:84534)
TypeError: Type 'NoneType' cannot be serialized.

0 个答案:

没有答案