Showing results for 
Search instead for 
Did you mean: 

How to set empty leaf in Python


When I try to get junos configuration using nso cli, it works:

admin@ncs# devices device vmx1 rpc rpc-get-configuration get-configuration config-text | display xml
<configuration-text xmlns='_juniper-junos-nc-4.6:juniper-junos-nc-4.6#urn:juniper-rpc'>## Last changed: 2021-06-02 22:48:40 UTC
version 18.2R1.9;
system {
root-authentication {
encrypted-password "xyz";
host-name VMX1;
services {
ssh {
root-login allow;



However, when i try to do the same from python, i found that i need to add empty leaf "config-text", otherwise the configuration is not returned.

I tried setting the leaf to "", but i get error that this element cannot be set.

How can i retrieve junos config from python ?


In [142]: action = device.rpc.jrpc__rpc_get_configuration.get_configuration

In [143]: input = action.get_input()

In [144]: input.config_text
Out[144]: Empty leaf name=config-text tag=249964986 cached=False

In [145]: print(action(input).configuration_text)

In [146]: input.config_text=''
MaagicError Traceback (most recent call last)
<ipython-input-146-9f18c6955582> in <module>
----> 1 input.config_text=''

/root/nso5.3/src/ncs/pyapi/ncs/ in __setattr__(self, name, value)
486 child.set_value(value)
487 else:
--> 488 raise MaagicError("Node type does not support assignment")
489 else:
490 raise MaagicError("Node has no attribute '%s'" % (name,))

MaagicError: Node type does not support assignment

In [147]:

1 Accepted Solution

Accepted Solutions

Cisco Employee
Cisco Employee
For empty leafs you use the create() method.

View solution in original post

3 Replies 3

Cisco Employee
Cisco Employee
For empty leafs you use the create() method.


Is there any way to filter the output for something like "show configuration protocols isis" only, instead of the full config ?

Or a way to retrieve the config in XML format, instead of free text ?

This is an rpc towards the juniper device, so all formatting except for the xml part is done on the juniper side, nso only receives a string from the device. This means that any formatting options will depends on what is available in the rpc.
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 NSO Developer community:

Recognize Your Peers