05-19-2023 12:25 AM
Hi guys,
I get the below error when I try to make a connection to my CSRv router.
Traceback (most recent call last):
File "C:\Windows\system32\Netconf_env\Scripts\mdp_home_test\get_interface_list_home.py", line 56, in <module>
netconf_reply = m.get_config(source = 'running', filter = netconf_filter)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Windows\system32\Netconf_env\Lib\site-packages\ncclient\manager.py", line 212, in execute
return cls(self._session,
^^^^^^^^^^^^^^^^^^
File "C:\Windows\system32\Netconf_env\Lib\site-packages\ncclient\operations\retrieve.py", line 166, in request
return self._request(node)
^^^^^^^^^^^^^^^^^^^
File "C:\Windows\system32\Netconf_env\Lib\site-packages\ncclient\operations\rpc.py", line 341, in _request
raise self._reply.error
ncclient.operations.rpc.RPCError: {'type': 'protocol', 'tag': 'unknown-element', '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}
Here is my code below:
05-19-2023 01:57 AM - edited 05-19-2023 01:58 AM
Remove the filter tags from your payload and explicit define subtree filtering in the get_config method:
netconf_filter = """
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface/>
</interfaces>
"""
# Open a connection to the network device using ncclient
with manager.connect(
device_params={'name':'csr'},
host= "192.168.0.124",
port= 830,
username= "admin",
password= "Test123",
hostkey_verify=False
) as m:
print("Sending a <get-config> operation to the device.\n")
# Make a NETCONF <get-config> query using the filter
netconf_reply = m.get_config(source = 'running', filter=("subtree", netconf_filter)
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