07-13-2022 02:04 PM
I'm try to configure a loopback interface using ncclient but I get the following error message
Error message after executing python script
PS C:\Users\nb303g\Documents\Python Projects\PY\ncclient> python.exe .\main_iosxr_working.py
Traceback (most recent call last):
File "C:\Users\nb303g\Documents\Python Projects\PY\ncclient\main_iosxr_working.py", line 98, in <module>
data = cisco_manager.edit_config ( interfacecfg, target='candidate')
File "C:\Users\nb303g\AppData\Local\Programs\Python\Python310\lib\site-packages\ncclient\manager.py", line 246, in execute
node.append(validated_element(config, ("config", qualify("config"))))
File "C:\Users\nb303g\AppData\Local\Programs\Python\Python310\lib\site-packages\ncclient\xml_.py", line 150, in validated_element
ele = to_ele(x)
File "C:\Users\nb303g\AppData\Local\Programs\Python\Python310\lib\site-packages\ncclient\xml_.py", line 129, in to_ele
return x if etree.iselement(x) else etree.fromstring(x.encode('UTF-8'), parser=_get_parser(huge_tree))
File "src\lxml\etree.pyx", line 3254, in lxml.etree.fromstring
File "src\lxml\parser.pxi", line 1913, in lxml.etree._parseMemoryDocument
File "src\lxml\parser.pxi", line 1800, in lxml.etree._parseDoc
File "src\lxml\parser.pxi", line 1141, in lxml.etree._BaseParser._parseDoc
File "src\lxml\parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
File "src\lxml\parser.pxi", line 725, in lxml.etree._handleParseResult
File "src\lxml\parser.pxi", line 654, in lxml.etree._raiseParseError
File "<string>", line 4
lxml.etree.XMLSyntaxError: AttValue: " or ' expected, line 4, column 99
Solved! Go to Solution.
07-27-2022 03:08 PM - edited 07-29-2022 01:02 PM
Hello,
You get this issue because your aren't using normal quote in operation merge. I get the same issue by using your payload. I changed it and now i didn't get the error.
interfacecfg = """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg" xc:operation="merge">
<interface-configuration>
<interface-name>Loopback100</interface-name>
<interface-virtual/>
<ipv4-network xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-io-cfg">
<addresses>
<primary>
<address>10.99.1.99</address>
<netmask>255.255.255.255</netmask>
</primary>
</addresses>
</ipv4-network>
</interface-configuration>
</interface-configurations>
</config>
"""
You can also check your payload using a text edit nano/vi/vim and you will see that's quote are missing .
Here a screenshot
07-29-2022 02:06 PM - edited 07-29-2022 02:12 PM
From your log it's look like that you are facing permission issue.
Jul 27 18:08:56.280 netconf-yfw/nacm.trace 0/RP0/CPU0 t8508 #18876: TRC: yfw_nacm_req_author_enforcement:1421 ctx=0x5576a3f36770,Req <edit-config> is denied (rpc-name)
Can you execute the command
show nacm summary
Here a link that might help you
07-14-2022 02:53 AM
No sure if this is the same, but take a look at this thread, https://community.cisco.com/t5/other-networking-subjects/attributeerror-rpcreply-object-has-no-attribute-data-ele/m-p/4560220
07-15-2022 09:11 AM
I've downgraded ncclient from 0.6.13 to 0.6.4 but I still get the same error.
PS C:\Users\nb303g\Documents\Python Projects\PY\ncclient> pip show ncclient
Name: ncclient
Version: 0.6.4
Summary: Python library for NETCONF clients
Home-page: https://github.com/ncclient/ncclient
07-15-2022 09:14 AM
I have no problem getting the config from the router but i'm unable to edit the config.
07-18-2022 01:57 AM
Try to remove the outer most tag (<edit-config>..</edit-config>) from the payload:
interfacecfg = """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg" xc:operation=”merge”>
<interface-configuration>
<interface-name>Loopback100</interface-name>
<interface-virtual/>
<ipv4-network xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-io-cfg">
<addresses>
<primary>
<address>10.99.1.99</address>
<netmask>255.255.255.255</netmask>
</primary>
</addresses>
</ipv4-network>
</interface-configuration>
</interface-configurations>
</config>
"""
HTH
Marcel
07-18-2022 07:52 AM
@Marcel Zehnder Removing the outer tags didn't make any difference. I still got the error
lxml.etree.XMLSyntaxError: AttValue: " or ' expected, line 4, column 99
07-27-2022 03:08 PM - edited 07-29-2022 01:02 PM
Hello,
You get this issue because your aren't using normal quote in operation merge. I get the same issue by using your payload. I changed it and now i didn't get the error.
interfacecfg = """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg" xc:operation="merge">
<interface-configuration>
<interface-name>Loopback100</interface-name>
<interface-virtual/>
<ipv4-network xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-io-cfg">
<addresses>
<primary>
<address>10.99.1.99</address>
<netmask>255.255.255.255</netmask>
</primary>
</addresses>
</ipv4-network>
</interface-configuration>
</interface-configurations>
</config>
"""
You can also check your payload using a text edit nano/vi/vim and you will see that's quote are missing .
Here a screenshot
07-29-2022 11:25 AM - edited 07-29-2022 11:27 AM
The solution you have suggested kinda worked. After editing the payload as per your suggestion, I'm no longer getting the old error "lxml.etree.XMLSyntaxError: AttValue: " or ' expected, line 4, column 99" but it's still not working for me. This time I get another error "ncclient.operations.rpc.RPCError: edit-config". May I know the ncclient and cisco NOS versions that you are using.?
Payload:-
07-29-2022 01:03 PM
Can you share the traceback ?
07-29-2022 01:24 PM
07-29-2022 02:01 PM
Can you share also the python traceback
07-29-2022 02:06 PM - edited 07-29-2022 02:12 PM
From your log it's look like that you are facing permission issue.
Jul 27 18:08:56.280 netconf-yfw/nacm.trace 0/RP0/CPU0 t8508 #18876: TRC: yfw_nacm_req_author_enforcement:1421 ctx=0x5576a3f36770,Req <edit-config> is denied (rpc-name)
Can you execute the command
show nacm summary
Here a link that might help you
08-01-2022 07:29 AM
Nabsh,
Really appreciate your help.It worked after enabling nacm and adding one more line to the payload "<active>act</active>"
RP/0/RP0/CPU0:router1#show nacm summary
NACM SUMMARY
--------------------------------------------------------------------------------
Enable Nacm : True
Enable External Groups : True
Number of Groups : 1
Number of Users : 1
Number of Rules : 0
Number of Rulelist : 0
Default Read : permit
Default Write : permit
Default Exec : permit
Denied Operations : 23
Denied Data Writes : 0
Denied Notifications : 0
--------------------------------------------------------------------------------
RP/0/RP0/CPU0:router1#show running-config nacm
nacm group tempnacm
usernames sam123
!
nacm write-default permit
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