cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3811
Views
0
Helpful
6
Replies

ncclient get_cofig filter error

pmlam3274
Level 2
Level 2

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}
>>>

 

6 Replies 6

@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.

 

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

kenmartinmiller
Visitor

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!

@kenmartinmiller what is the sandbox you are using (there is two always on xe) and code/error you get?

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Howdy! Using: 

sandbox-iosxe-latest-1.cisco.com

And 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!

@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.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

@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!