0

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

Please help me to solve this problem

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))    
kovalo
  • 1

1 Answers1

0

I don't have a solution yet, still working. But, try our this code below, if you are trying to write to a note_file.. It might help.

                response = m.managers[id].dispatch(rpc['rpc_template'])                    

                print("\n\n****************   Printing Response   ********************** ")
                print(response)
                print("\n**************** Response Printed ********************* ")

                directory = "results/"+vendor+"/"+tec+"/"+m.managers[id].host+"/"+rpc["operation"]
                file = open(directory + '/' + testcase[0] + '_rpc-reply.xml', 'w+')
                file = open(directory + '/' + testcase[0] + '_rpc-response.xml', 'w+')

                print("\n\n****************  Writing Response in Results file  ********************** ")
                file.write(etree.tostring(response,pretty_print=True))
                file.close()
                print("\n**************** Response Written to the file ********************* ")
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 10 '22 at 17:06