09-06-2021 11:24 PM
Does anyone know why i am getting an error on get_config with ncclient? may be the filter i am using is not right but the filter is from the iosxe lab.
netconf_filter = """
<filter>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface></interface>
</interfaces>
</filter>"""
m = manager.connect(
host="10.10.20.100",
port="830",
username="developer",
password="C1sco12345",
hostkey_verify=False
)
netconf_reply = m.get_config(source = 'running', filter = netconf_filter)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lam/DEVNET-Lab/netconf/lib/python3.8/site-packages/ncclient/manager.py", line 246, in execute
return cls(self._session,
File "/home/lam/DEVNET-Lab/netconf/lib/python3.8/site-packages/ncclient/operations/retrieve.py", line 166, in request
return self._request(node)
File "/home/lam/DEVNET-Lab/netconf/lib/python3.8/site-packages/ncclient/operations/rpc.py", line 375, in _request
raise self._reply.error
ncclient.operations.rpc.RPCError: {'type': 'protocol', 'tag': 'unknown-element', 'app_tag': None, 'severity': 'error', 'info': '<?xml version="1.0" encoding="UTF-8"?><error-info xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><bad-element>filter</bad-element>\n</error-info>\n', 'path': '\n /rpc/get-config\n ', 'message': None}
>>>
09-06-2021 11:31 PM
@pmlam3274 which learning lab are you following? There was an issue with one of the always-on XE sandbox rejecting RESTCONF/NetConf at one stage.
01-11-2022 03:49 AM
Howdy - were you able to get this resolved? I'm running into the same issue when attempting to pull data using an XML filter from the DevNet always on XE sandbox. Thanks!
01-11-2022 06:17 AM
@kenmartinmiller what is the sandbox you are using (there is two always on xe) and code/error you get?
01-11-2022 06:32 AM
Howdy! Using:
sandbox-iosxe-latest-1.cisco.comAnd the error I'm getting is the same as OP:
<error-info xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><bad-element>filter</bad-element>\n</error-info>
"Bad element". I can get_config with no filters just fine, but when I add an XML filter, I get the above error. Relatively new to doing this, so error could be on my end. Thanks for the help!
01-11-2022 07:09 AM
@kenmartinmiller it depends on what data you are wanting, typically i use the native model
<config>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<router>
<ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf">
</ospf>
</router>
</native>
</config>
And then print the output
reply = m.get_config(rpc, target='running')
print(reply)
Take a look at YANG suite, https://developer.cisco.com/yangsuite/
Hope this helps.
01-13-2022 02:52 AM
@bigevilbeard thanks again for the help! Figured this out. 2 problems:
1. I was targeting sandbox-iosxe-latest-1.cisco.com, which is currently running 17.3.1, which has a known issue with this exact scenario, documented here: https://community.cisco.com/t5/yang-tools/netconf-error-on-csr-1000v/td-p/4264458. Once I targeted sandbox-iosxe-recomm-1.cisco.com instead, which is running 16.9.3, the query started working.
2. Instead of writing out the full XML filter, I started using xpath filtering. For example:
# Filter specific info
config = xml.dom.minidom.parseString(str(m.get_config(source='running', filter=('xpath', '/native/router/ospf'))))
print(config.toprettyxml(indent = " "))
This returns the OSPF configuration of the device. Thanks again for your help!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide