cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
462
Views
6
Helpful
1
Replies

Exception has occurred: RPCError

amiruka06
Level 1
Level 1

Hello all, Hope you're doing good.
I'm trying to netconf on my CSR1kv router which I have hosted on my ESXi server.

When I'm trying to debug this code:

from ncclient import manager
from devices import router1

netconf_filter = open("filter-ietf-interfaces.xml").read()

with manager.connect(host=router1["host"], port=router1["port"], username=router1["username"], password=router1["password"], hostkey_verify=False) as m:
    interface_netconf = m.get(netconf_filter)
    print('Getting running config')

I'm getting this error on response:

Exception has occurred: 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\n  ', 'message': None}
  File "C:\Users\aukka\Desktop\DevNetOps\NetConf\ncclient-1.py", line 33, in <module>
    interface_netconf = m.get(netconf_filter)

Obviously it seems that there's an error with m.get function.
Is there anyone who can help how I can fix this issue?
Thanks,

1 Reply 1

@amiruka06 check this thread on ncclient https://community.cisco.com/t5/application-centric/aci-config-xml-script/td-p/4032990

 

❯ pip freeze | grep ncc
ncclient==0.6.12

This code works

 

import lxml.etree as et
from ncclient import manager
from ncclient.operations import RPCError

payload = [
'''
<get-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <source>
    <running/>
  </source>
  <filter>
    <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
      <interface>
      </interface>
    </interfaces>
  </filter>
</get-config>
'''
]

# connect to netconf agent
with manager.connect(host="sandbox-iosxe-latest-1.cisco.com",
                         port="830",
                         username="developer",
                         password="C1sco12345",
                         timeout=90,
                         hostkey_verify=False,
                         device_params={'name': 'csr'}) as m:

        # execute netconf operation
        for rpc in payload:
           try:
                response = m.dispatch(et.fromstring(rpc))
                data = response.xml
           except RPCError as e:
               data = e._raw
        print(response.xml)

 

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