cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
769
Views
0
Helpful
15
Replies

Cisco NCS540 Netconf xml commands

Trying to start using netconf on cisco ncs540, but none of my commnad will work. I followed the instructions from this document, but it is not responding with any data. As you can see from the output below. I've tried many different convinations to get it to work, but nothing yet. Anybody has experience on this what could give me a hint

Programmability Configuration Guide for Cisco NCS 540 Series Routers, Cisco IOS XR Release 7.8.x

 

#418
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<filter>
<isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-oper">
<instances>
<instance>
<neighbors/>
<instance-name/>
</instance>
</instances>
</isis>
</filter>
</get>
</rpc>
]]>]]>
Entity: line 16: parser error : Extra content at the end of the document
##
^
ERROR: 0xa240fe00 'XML Infrastructure' detected the 'fatal' condition 'The XML document is not well-formed'
Line 16: Extra content at the end of the document

##

#418
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<filter>
<isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-oper">
<instances>
<instance>
<neighbors/>
<instance-name/>
</instance>
</instances>
</isis>
</filter>
</get>
</rpc>
##


#411
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<filter>
<isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-oper">
<instances>
<instance>
<neighbors/>
<instance-name/>
</instance>
</instances>
</isis>
</filter>
</get>
</rpc>
##

 

 

#371
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<filter>
<isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-oper">
<instances>
<instance>
<neighbors/>
<instance-name/>
</instance>
</instances>
</isis>
</filter>
</get>
</rpc>

##
#371
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<filter>
<isis xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-clns-isis-oper">
<instances>
<instance>
<neighbors/>
<instance-name/>
</instance>
</instances>
</isis>
</filter>
</get>
</rpc>
##


#212
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<ping xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ping-act">
<destination>
<destination>1.2.3.4</destination>
</destination>
</ping>
</rpc>
##


i
^H'


i#251
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<ping xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ping-act">
<destination>
<destination>1.2.3.4</destination>
</destination>
</ping>
</rpc>
##

^Croot@orl-vm-dev-awx-01:~# ssh dxg5emergency@10.205.0.122 -p 22 -s netconf

CC
*****************************************************************************
* *
* !!! ATTENTION !!! THIS IS A PRODUCTION SYSTEM !!! *
* *
* This network is protected by a security system. Criminal law *
* prohibits unauthorized use. If you are not specifically authorized *
* to access data on this system, disconnect now. *
* *
* Pursuant to 18 U.S.C. section 2510, all information and *
* communications on this system are subject to review, monitoring, *
* and recording at any time without notice or permission. *
* *
* Unauthorized use or access may be subject to prosecution or *
* disciplinary action. *
* *
*****************************************************************************


Password:


Mon Jun 3 08:28:40.076 EDT
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>
urn:ietf:params:netconf:base:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:candidate:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:notification:1.0
</capability>
</capabilities>
<session-id>
285212672
</session-id>
</hello>
]]>]]>
#251
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<ping xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ping-act">
<destination>
<destination>1.2.3.4</destination>
</destination>
</ping>
</rpc>
##

 


<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<ping xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ping-act">
<destination>
<destination>1.2.3.4</destination>
</destination>
</ping>
</rpc>

<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<ping xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ping-act">
<destination>
<destination>1.2.3.4</destination>
</destination>
</ping>
</rpc>


#274
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<ping xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ping-act">
<destination>
<destination>1.2.3.4</destination>
</destination>
</ping>
</rpc>
##


^Croot@orl-vm-dev-awx-01:~# ssh dxg5emergency@10.205.0.122 -p 22 -s netconf

CC
*****************************************************************************
* *
* !!! ATTENTION !!! THIS IS A PRODUCTION SYSTEM !!! *
* *
* This network is protected by a security system. Criminal law *
* prohibits unauthorized use. If you are not specifically authorized *
* to access data on this system, disconnect now. *
* *
* Pursuant to 18 U.S.C. section 2510, all information and *
* communications on this system are subject to review, monitoring, *
* and recording at any time without notice or permission. *
* *
* Unauthorized use or access may be subject to prosecution or *
* disciplinary action. *
* *
*****************************************************************************


Password:


Mon Jun 3 08:31:24.054 EDT
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>
urn:ietf:params:netconf:base:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:candidate:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:notification:1.0
</capability>
</capabilities>
<session-id>
285212672
</session-id>
</hello>
]]>]]>
#274
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<ping xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ping-act">
<destination>
<destination>1.2.3.4</destination>
</destination>
</ping>
</rpc>
##

 

#535
<rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<source>
<running/>
</source>
<filter>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\>
<interface-configuration>
<active>act</active>
<interface-name>TenGigE0/0/0/2</interface-name>
</interface-configuration>
</interface-configurations>
</filter>
</get-config>
</rpc>
##
^Croot@orl-vm-dev-awx-01:~# ssh dxg5emergency@10.205.0.122 -p 22 -s netconf

CC
*****************************************************************************
* *
* !!! ATTENTION !!! THIS IS A PRODUCTION SYSTEM !!! *
* *
* This network is protected by a security system. Criminal law *
* prohibits unauthorized use. If you are not specifically authorized *
* to access data on this system, disconnect now. *
* *
* Pursuant to 18 U.S.C. section 2510, all information and *
* communications on this system are subject to review, monitoring, *
* and recording at any time without notice or permission. *
* *
* Unauthorized use or access may be subject to prosecution or *
* disciplinary action. *
* *
*****************************************************************************


!@M&A$0m3n3ng!3r^H^H^H^H^H^H
Password:


Mon Jun 3 08:42:26.734 EDT
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>
urn:ietf:params:netconf:base:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:candidate:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:notification:1.0
</capability>
</capabilities>
<session-id>
285212672
</session-id>
</hello>
]]>]]>
#535
<rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<source>
<running/>
</source>
<filter>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\>
<interface-configuration>
<active>act</active>
<interface-name>TenGigE0/0/0/2</interface-name>
</interface-configuration>
</interface-configurations>
</filter>
</get-config>
</rpc>
##


#477
<rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<filter>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\>
<interface-configuration>
<active>act</active>
<interface-name>TenGigE0/0/0/2</interface-name>
</interface-configuration>
</interface-configurations>
</filter>
</get-config>
</rpc>
##

 


^Croot@orl-vm-dev-awx-01:~# #
root@orl-vm-dev-awx-01:~# <rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# <get-config>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# <filter>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\>
-bash: interface-configurations: No such file or directory
root@orl-vm-dev-awx-01:~# <interface-configuration>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# <active>act</active>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# <interface-name>TenGigE0/0/0/2</interface-name>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# </interface-configuration>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# </interface-configurations>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# </filter>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# </get-config>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# </rpc>
-bash: syntax error near unexpected token `newline'
root@orl-vm-dev-awx-01:~# ##
root@orl-vm-dev-awx-01:~#
root@orl-vm-dev-awx-01:~# <rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">^C
root@orl-vm-dev-awx-01:~#
root@orl-vm-dev-awx-01:~# ssh dxg5emergency@10.205.0.122 -p 22 -s netconf

CC
*****************************************************************************
* *
* !!! ATTENTION !!! THIS IS A PRODUCTION SYSTEM !!! *
* *
* This network is protected by a security system. Criminal law *
* prohibits unauthorized use. If you are not specifically authorized *
* to access data on this system, disconnect now. *
* *
* Pursuant to 18 U.S.C. section 2510, all information and *
* communications on this system are subject to review, monitoring, *
* and recording at any time without notice or permission. *
* *
* Unauthorized use or access may be subject to prosecution or *
* disciplinary action. *
* *
*****************************************************************************


Password:


Mon Jun 3 08:43:55.427 EDT
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>
urn:ietf:params:netconf:base:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:candidate:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:notification:1.0
</capability>
</capabilities>
<session-id>
285212672
</session-id>
</hello>
]]>]]>
#517
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<filter>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\>
<interface-configuration>
<active>act</active>
<interface-name>TenGigE0/0/0/2</interface-name>
</interface-configuration>
</interface-configurations>
</filter>
</get-config>
</rpc>
##

 

#517
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get>
<filter>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\>
<interface-configuration>
<active>act</active>
<interface-name>TenGigE0/0/0/2</interface-name>
</interface-configuration>
</interface-configurations>
</filter>
</get>
</rpc>
##


#517
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<filter>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\>
<interface-configuration>
<active>act</active>
<interface-name>TenGigE0/0/0/2</interface-name>
</interface-configuration>
</interface-configurations>
</filter>
</get-config>
</rpc>
##


^C^Croot@orl-vm-dev-awx-01:~# ssh dxg5emergency@10.205.0.122 -p 22 -s netconf

CC
*****************************************************************************
* *
* !!! ATTENTION !!! THIS IS A PRODUCTION SYSTEM !!! *
* *
* This network is protected by a security system. Criminal law *
* prohibits unauthorized use. If you are not specifically authorized *
* to access data on this system, disconnect now. *
* *
* Pursuant to 18 U.S.C. section 2510, all information and *
* communications on this system are subject to review, monitoring, *
* and recording at any time without notice or permission. *
* *
* Unauthorized use or access may be subject to prosecution or *
* disciplinary action. *
* *
*****************************************************************************


Password:


Mon Jun 3 09:04:47.816 EDT
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>
urn:ietf:params:netconf:base:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:candidate:1.0
</capability>
<capability>
urn:ietf:params:netconf:capability:notification:1.0
</capability>
</capabilities>
<session-id>
285212672
</session-id>
</hello>
]]>]]>
#517
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101"xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<filter>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\>
<interface-configuration>
<active>act</active>
<interface-name>TenGigE0/0/0/2</interface-name>
</interface-configuration>
</interface-configurations>
</filter>
</get-config>
</rpc>
##

1 Accepted Solution

Accepted Solutions

Found the problem. it was the command   ssh server capability netconf-xml . Now it's working 

RP/0/RP0/CPU0:SCTLAB-NCS540-01(config)#no ssh server capability netconf-xml
RP/0/RP0/CPU0:SCTLAB-NCS540-01(config)#commit
Mon Jun 3 14:29:29.743 EDT

 

View solution in original post

15 Replies 15

Based on the error message you're seeing, it seems that the XML data you're sending is not well-formed, which is causing the Netconf server to return an error. Specifically, the error message indicates that there is "Extra content at the end of the document" which suggests that there is some unexpected data after the closing tag of your XML document. Looking at your XML requests, I notice that some of them have extra "##" characters at the end of the document. This extra data is causing the XML document to be malformed, which is likely causing the Netconf server to return an error. To fix this issue, you should ensure that your XML documents are well-formed and do not contain any extra data beyond the closing tag. 

Can you share one piece of python code with a simple example you are using, once this is working you can update with other requests/configuration.

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

I've had not been able to get it to work thru python yet.  I was able to get the session authenticated.  I wanted to at least get to work via ssh.  I use the xml formatter  to make sure that the data does not have any identation issues. I literally flowing the example shown in the screenshoot.

 

 

 

def connect_to_cisco_netconf(cisco_host_ip,sct_username,sct_password
    cisco_connection = manager.connect(host= cisco_host_ip,
                                       port=22,
                                       username=sct_username,
                                       password=sct_password,
                                       hostkey_verify = False,
                                       device_params={'name':'iosxr'},
                                       allow_agent=False
                                       )
    for capability in cisco_connection.server_capabilities:
        print(capability)
   
    print(str(cisco_connection.connected))
    return(cisco_connection)
Manager.get_config
cisco_connection = connect_to_cisco_netconf(cisco_host_ip,sct_username,sct_password)
 

>>> interface_config.close()
>>>
>>> interface_config_command
'<filter>\n <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\\>\n <interface-configuration>\n <active>act</active>\n <interface-name>TenGigE0/0/0/2</interface-name>\n </interface-configuration>\n </interface-configurations>\n</filter>\n'
>>> xml_commands_send = Manager.get_config('running',interface_config_command)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\netconf_client\ncclient.py", line 321, in get_config
(raw, ele) = self._send_rpc(rpc_xml)
^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute '_send_rpc'
>>>

 

 

Thanks, so i see the error you're encountering is due you are trying to call a method (get_config) on a class (Manager), rather than on an instance of that classIn your code, Manager is likely a class from the ncclient library, and get_config is an instance method of that class. You need to create an instance of the Manager class and then call the get_config method on that instance. Try this (update for your needs)

from ncclient import manager

def connect_to_cisco_netconf(cisco_host_ip, sct_username, sct_password):
    cisco_connection = manager.connect(host=cisco_host_ip,
                                       port=22,
                                       username=sct_username,
                                       password=sct_password,
                                       hostkey_verify=False,
                                       device_params={'name':'iosxr'},
                                       allow_agent=False
                                       )
    for capability in cisco_connection.server_capabilities:
        print(capability)
   
    print(str(cisco_connection.connected))
    return cisco_connection

cisco_connection = connect_to_cisco_netconf(cisco_host_ip, sct_username, sct_password)

interface_config_command = '<filter>\n <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\\>\n <interface-configuration>\n <active>act</active>\n <interface-name>TenGigE0/0/0/2</interface-name>\n </interface-configuration>\n </interface-configurations>\n</filter>\n'

xml_commands_send = cisco_connection.get_config('running', filter=('subtree', interface_config_command))

 

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

Tried thie before, and got this error.:

 

>>>
>>>
>>> from ncclient import manager
>>>
>>> cisco_host_ip = '10.0.99.200'
>>> sct_username = 'XXXXXXXXX'
>>> sct_password = 'XXXXXXXXX'
>>> def connect_to_cisco_netconf(cisco_host_ip, sct_username, sct_password):
... cisco_connection = manager.connect(host=cisco_host_ip,
... port=22,
... username=sct_username,
... password=sct_password,
... hostkey_verify=False,
... device_params={'name':'iosxr'},
... allow_agent=False
... )
... for capability in cisco_connection.server_capabilities:
... print(capability)
...
... print(str(cisco_connection.connected))
... return cisco_connection
...
>>> cisco_connection = connect_to_cisco_netconf(cisco_host_ip, sct_username, sct_password)
urn:ietf:params:netconf:base:1.0
urn:ietf:params:netconf:base:1.1
urn:ietf:params:netconf:capability:writable-running:1.0
urn:ietf:params:netconf:capability:candidate:1.0
urn:ietf:params:netconf:capability:confirmed-commit:1.0
urn:ietf:params:netconf:capability:rollback-on-error:1.0
urn:ietf:params:netconf:capability:startup:1.0
urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file,https,sftp
urn:ietf:params:netconf:capability:validate:1.0
urn:ietf:params:netconf:capability:xpath:1.0
urn:ietf:params:netconf:capability:notification:1.0
urn:ietf:params:netconf:capability:interleave:1.0
urn:ietf:params:netconf:capability:with-defaults:1.0
True
>>> interface_config_command = '<filter>\n <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"\\>\n <interface-configuration>\n <active>act</active>\n <interface-name>TenGigE0/0/0/2</interface-name>\n </interface-configuration>\n </interface-configurations>\n</filter>\n'
>>>
>>> xml_commands_send = cisco_connection.get_config('running', filter=('subtree', interface_config_command))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\manager.py", line 257, in execute
return cls(self._session,
^^^^^^^^^^^^^^^^^^
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\operations\retrieve.py", line 158, in request
node.append(util.build_filter(filter))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\operations\util.py", line 65, in build_filter
rep.append(to_ele(criteria))
^^^^^^^^^^^^^^^^
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\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 3264, in lxml.etree.fromstring
File "src\lxml\parser.pxi", line 1916, in lxml.etree._parseMemoryDocument
File "src\lxml\parser.pxi", line 1803, in lxml.etree._parseDoc
File "src\lxml\parser.pxi", line 1144, in lxml.etree._BaseParser._parseDoc
File "src\lxml\parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc
File "src\lxml\parser.pxi", line 728, in lxml.etree._handleParseResult
File "src\lxml\parser.pxi", line 657, in lxml.etree._raiseParseError
File "<string>", line 2
lxml.etree.XMLSyntaxError: attributes construct error, line 2, column 83
>>>

Hi @DanielGutierrez615 

Try to remove the filter-tag from your subtree:

interface_config_command = '''
    <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
        <interface-configuration>
          <active>act</active>
          <interface-name>TenGigE0/0/0/2</interface-name>
        </interface-configuration>
      </interface-configurations>'''

HTH
Marcel

Now I get this error

>>> cisco_connection = connect_to_cisco_netconf(cisco_host_ip, sct_username, sct_password)
urn:ietf:params:netconf:base:1.0
urn:ietf:params:netconf:base:1.1
urn:ietf:params:netconf:capability:writable-running:1.0
urn:ietf:params:netconf:capability:candidate:1.0
urn:ietf:params:netconf:capability:confirmed-commit:1.0
urn:ietf:params:netconf:capability:rollback-on-error:1.0
urn:ietf:params:netconf:capability:startup:1.0
urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file,https,sftp
urn:ietf:params:netconf:capability:validate:1.0
urn:ietf:params:netconf:capability:xpath:1.0
urn:ietf:params:netconf:capability:notification:1.0
urn:ietf:params:netconf:capability:interleave:1.0
urn:ietf:params:netconf:capability:with-defaults:1.0
True
>>> xml_commands_send = cisco_connection.get_config('running', filter=('subtree', interface_config_command))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\manager.py", line 257, in execute
return cls(self._session,
^^^^^^^^^^^^^^^^^^
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\operations\retrieve.py", line 166, in request
return self._request(node)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\operations\rpc.py", line 381, in _request
raise TimeoutExpiredError('ncclient timed out while waiting for an rpc reply.')
ncclient.operations.errors.TimeoutExpiredError: ncclient timed out while waiting for an rpc reply.

That looks its just timing out, is netconf enabled on the device and you get a response back ok?

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

Stuck here 

>>> def connect_to_cisco_netconf(cisco_host_ip, sct_username, sct_password):
... cisco_connection = manager.connect(host=cisco_host_ip,
... port=22,
... username=sct_username,
... password=sct_password,
... hostkey_verify=False,
... device_params={'name':'iosxr'},
... allow_agent=False,
... timeout=300)
... for capability in cisco_connection.server_capabilities:
... print(capability)
...
... print(str(cisco_connection.connected))
... return cisco_connection
...
>>> cisco_connection = connect_to_cisco_netconf(cisco_host_ip, sct_username, sct_password)
urn:ietf:params:netconf:base:1.0
urn:ietf:params:netconf:base:1.1
urn:ietf:params:netconf:capability:writable-running:1.0
urn:ietf:params:netconf:capability:candidate:1.0
urn:ietf:params:netconf:capability:confirmed-commit:1.0
urn:ietf:params:netconf:capability:rollback-on-error:1.0
urn:ietf:params:netconf:capability:startup:1.0
urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file,https,sftp
urn:ietf:params:netconf:capability:validate:1.0
urn:ietf:params:netconf:capability:xpath:1.0
urn:ietf:params:netconf:capability:notification:1.0
urn:ietf:params:netconf:capability:interleave:1.0
urn:ietf:params:netconf:capability:with-defaults:1.0
True
>>> xml_commands_send = cisco_connection.get_config('running', filter=('subtree', interface_config_command))

 

 

What if you just wait? Now the timeout is 5min, after 5min you get an error message/traceback?

Same thing. There has to be something I'm missing I just don't know what it is 

>>> cisco_connection.connected
True
>>> interface_config_command
'\n<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">\n <interface-configuration>\n <active>act</active>\n <interface-name>TenGigE0/0/0/2</interface-name>\n </interface-configuration>\n</interface-configurations>\n'
>>> xml_commands_send = cisco_connection.get_config('running', filter=('subtree', interface_config_command))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\manager.py", line 257, in execute
return cls(self._session,
^^^^^^^^^^^^^^^^^^
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\operations\retrieve.py", line 166, in request
return self._request(node)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\dgutierrez\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ncclient\operations\rpc.py", line 381, in _request
raise TimeoutExpiredError('ncclient timed out while waiting for an rpc reply.')
ncclient.operations.errors.TimeoutExpiredError: ncclient timed out while waiting for an rpc reply.
>>>

ok, maybe the response is pretty large - try to raise the timeout for your session:

   cisco_connection = manager.connect(host=cisco_host_ip,
                                       port=22,
                                       username=sct_username,
                                       password=sct_password,
                                       hostkey_verify=False,
                                       device_params={'name':'iosxr'},
                                       allow_agent=False,
                                      timeout=300
                                       )

it is authenticating and looks like it's enabled

RP/0/RP0/CPU0:SCTLAB-NCS540-01#SHOW NETConf SEssions
Mon Jun 3 11:01:53.449 EDT
Session Client Agent User Date State
285212672 10.190.0.3 tty dxg5emergency Mon Jun 03 10:39:19 2024 Idle
285212673 10.7.224.41 tty dxg5emergency Mon Jun 03 11:00:10 2024 Idle
285212674 10.190.0.3 tty dxg5emergency Mon Jun 03 10:55:06 2024 Idle
285212675 10.190.0.3 tty dxg5emergency Mon Jun 03 11:01:14 2024 Idle

 

RP/0/RP0/CPU0:SCTLAB-NCS540-01#show netconf-yang status
Mon Jun 3 11:03:39.483 EDT
Netconf status summary:
state: ready
RP/0/RP0/CPU0:SCTLAB-NCS540-01#

Also make sure to close the session with cisco_connection.close_session() at the end of your script, otherwhise you may run into locking issues as well.

I'm also trying to following this video instructions, and I have not luck. 

IOSXR-netconf netconf RPC request to IOS XR via CLI (youtube.com)