cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1544
Views
5
Helpful
1
Replies

AttributeError: 'RPCReply' object has no attribute 'data_ele'

kovalov
Level 1
Level 1

Hi,

 

I'm getting this error" AttributeError: 'RPCReply' object has no attribute 'data_ele'" when I try to run the below script

import lxml.etree as et
from argparse import ArgumentParser
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>
        <name>GigabitEthernet1</name>
        <description/>
      </interface>
    </interfaces>
  </filter>
</get-config>
''',
]

# connect to netconf agent
with manager.connect(host="sandbox-iosxe-recomm-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.data_ele
            except RPCError as e:
                data = e._raw

            # beautify output
            print(et.tostring(data, encoding='unicode', pretty_print=True))
1 Reply 1

@kovalov your code is good. I think your issue here is ncclient version. Looks like "data_ele" might have been completely removed in ncclient==0.6.12 according to the error. This script work with ncclient==0.6.4. It looked like the API guide is referring to response.xml instead of response.data_ele.

 

~/Desktop on  master [✘!?⇡] via  v3.6.5 (venv) took 2s
❯ pip freeze | grep ncc
ncclient==0.6.4 ❯ python netconf_tester.py <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> <interface> <name>GigabitEthernet1</name> <description>MANAGEMENT INTERFACE - DON'T TOUCH ME</description> </interface> </interfaces> </data>

 

 

~/Desktop on  master [✘!?⇡] via  v3.8.0 (new_venv) took 3s
❯ pip freeze | grep ncc
ncclient==0.6.12 ❯ python netconf_tester.py Traceback (most recent call last): File "netconf_tester.py", line 38, in <module> data = response.data_ele AttributeError: 'RPCReply' object has no attribute 'data_ele'

To save the downgrade, update this part

 

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

            # beautify output
        print(response.xml)

The function lxml.tostring converts lxml objects to strings and the response.data_ele were lxml objects. XML is always a string so you can just print(response.xml).

 

 

❯ python netconf_tester.py
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:4cf416e4-cb0c-4f96-8583-18e291f0e083" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><data><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>GigabitEthernet1</name><description>MANAGEMENT INTERFACE - DON'T TOUCH ME</description></interface></interfaces></data></rpc-reply>

 

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