02-26-2022 08:07 AM
Hi,
I'm getting this error" AttributeError: 'RPCReply' object has no attribute 'data_ele'" when I try to run the below script
02-28-2022 06:02 AM
@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 [✘!?⇡] viav3.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 [✘!?⇡] viav3.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>
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