cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2026
Views
5
Helpful
12
Replies

IOS-XR 7.6.x Netconf: Unable to push config with ncclient

bnikhileshwar
Level 1
Level 1

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

 
Python Script
 
from ncclient import manager
host = '135.16.244.171'
cisco_manager = manager.connect (host= hostport=22username= username password=password                     hostkey_verify=Falsedevice_params={'name': 'iosxr'}, timeout = 5000allow_agent=Falselook_for_keys=False)
 
interfacecfg = """
<edit-config>
  <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/>
     <addresses>
      <primary>
       <address>10.99.1.99</address>
       <netmask>255.255.255.255</netmask>
      </primary>
     </addresses>
    </ipv4-network>
   </interface-configuration>
  </interface-configurations>
  </config>
</edit-config>
"""
data = cisco_manager.edit_config ( interfacecfg, target='candidate')
print (data)
reply = cisco_manager.commit()
cisco_manager.close_session()
2 Accepted Solutions

Accepted Solutions

Nabsch
Spotlight
Spotlight

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 

 

 

netconf.jpg

 

View solution in original post

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 

 

View solution in original post

12 Replies 12

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

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

bnikhileshwar
Level 1
Level 1

@bigevilbeard 

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

I have no problem getting the config from the router but i'm unable to edit the config. 

Marcel Zehnder
Spotlight
Spotlight

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

@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

Nabsch
Spotlight
Spotlight

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 

 

 

netconf.jpg

 

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:-

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>Loopback99</interface-name>
    <interface-virtual/>
     <addresses>
      <primary>
       <address>10.99.1.99</address>
       <netmask>255.255.255.255</netmask>
      </primary>
     </addresses>
    </ipv4-network>
   </interface-configuration>
  </interface-configurations>
 </config>
"""

 

Can you share the traceback ?

I have attached tracebacks

Can you share also the python traceback

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 

 

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

 

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>
    <active>act</active>
    <interface-name>Loopback99</interface-name>
    <interface-virtual/>
     <addresses>
      <primary>
       <address>10.99.1.99</address>
       <netmask>255.255.255.255</netmask>
      </primary>
     </addresses>
    </ipv4-network>
   </interface-configuration>
  </interface-configurations>
 </config>
"""
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: