02-03-2022 10:55 AM
Hello, I'm running IOS XE 16.9.4 on a Catalyst 9300. I'm trying to build a few NETCONF scripts to get a better understanding of it. I've cobbled together a script from various examples just to test out pulling interface information, but I've hit a wall. I'm getting an RPC error that I can't find a solution for, and was hoping someone could point me in the right direction. Unfortunately, I have almost no experience with this, so I'm kind of treading water.
Error message:
Traceback (most recent call last): File "C:\automate\Network\netconftest.py", line 35, in <module> state_data = m.get(filter=interface_filter).xml File "C:\automate\Network\network_automation\lib\site-packages\ncclient\manager.py", line 246, in execute return cls(self._session, File "C:\automate\Network\network_automation\lib\site-packages\ncclient\operations\retrieve.py", line 91, in request return self._request(node) File "C:\automate\Network\network_automation\lib\site-packages\ncclient\operations\rpc.py", line 375, in _request raise self._reply.error ncclient.operations.rpc.RPCError: {'type': 'protocol', 'tag': 'access-denied', 'app_tag': None, 'severity': 'error', 'info': None, 'path': None, 'message': None}
Here's the script
from ncclient import manager from pprint import pprint import xmltodict import xml.dom.minidom router = { 'ip': '<redacted>', 'port': '830', 'username': '<redacted>', 'password': '<redacted>' } m = manager.connect(host=router['ip'], port=router['port'], username=router['username'], password=router['password'], device_params={'name':'iosxe'}, hostkey_verify=False) print(m.connected) my_ints = ["1/0/15","2/0/23"] for x in my_ints: interface_filter = ''' <filter> <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <interface> <GigabitEthernet> <name>'''+str(x)+'''</name> </GigabitEthernet> </interface> </native> </filter> ''' print (interface_filter) state_data = m.get(filter=interface_filter).xml print(xml.dom.minidom.parseString(state_data).toprettyxml()) #running_config = m.get_config('running', interface_filter).xml #print(xml.dom.minidom.parseString(running_config).toprettyxml()) m.close_session()
Thanks in advance
Solved! Go to Solution.
02-04-2022 07:29 AM
I finally figured it out. It was silly. It's because the user I was logging in with didn't have a high enough privilege level
02-04-2022 05:49 AM
I'm not a scripting guru but try changing the section
<interface> <GigabitEthernet> <name>'''+str(x)+'''</name> </GigabitEthernet> </interface>
to
<interfaces> <interface> <name>'''+str(x)+'''</name> </interface> </interfaces>
source: slides-edu-network-configuration-with-netconf-00.pdf (ietf.org)
02-04-2022 07:03 AM
Hello,
That was a good thought, but unfortunately, I still received the same error message. Thanks for the reply, though!
02-04-2022 07:29 AM
I finally figured it out. It was silly. It's because the user I was logging in with didn't have a high enough privilege level
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