Junos
Highlighted
Junos

Junos - python : operation not permitted

‎10-31-2018 09:21 PM

I have reserved Standalone vMX in Juniper lab. I want to test running python code on Junos.

 

 

When I am running command python or python or python --version or running simple hello python program then it is giving error "/usr/bin/python: Operation not permitted."

 

PFA.

 

Please help me to fix this issue.

5 REPLIES 5
Highlighted
Junos

Re: Junos - python : operation not permitted

‎10-31-2018 10:39 PM

Hi

 

Python interactive mode is not supported on-box on a Junos device. Instead you can run scripts from files. See e.g. Recipe 17 in "Day One: Junos PyEZ Cookbook" (you can download in for free from https://www.juniper.net/uk/en/training/jnbooks/day-one/automation-series/junos-pyez-cookbook/).

 

If you want to use Python interactive mode with Junos/PyEZ, you  still can do it from remote server (Linux, etc.)

 

Best Regards,
PK

Juniper Ambassador, Juniper Networks Certified Instructor,
JNCIE-SEC #98, JNCIE-ENT #393, JNCIE-SP #2253
Twitter: @JuniperTrain
GitHub: https://github.com/pklimai
[Juniper Authorized Education & Support in Russia]
Highlighted
Junos

Re: Junos - python : operation not permitted

‎11-01-2018 12:03 AM

I tried to run simple hellowolrd python program but it stil gives the same error operation not permitted

Highlighted
Junos

Re: Junos - python : operation not permitted

‎11-01-2018 03:06 AM

Hi 

 

I assume this may be due to inappropriate permissions for Python file. Generally it should be something like this, for device_info.py script:

lab@vMX-1> file list /var/db/scripts/op/ detail | match device_info.py 
-rw-r--r--  1 lab   wheel        309 Jul 19  2017 device_info.py

I.e., write permissions must only be available for script owner. See the following URL for more details on permissions and running scripts: 

https://www.juniper.net/documentation/en_US/junos/topics/reference/general/junos-script-automation-p...

 

Then you will be able to run the script as follows

lab@vMX-1> op device_info.py 
Model: VMX
Serial number: VMXXXXXXXX

You also need to have the following configured

lab@vMX-1# show system scripts 
op {
    file device_info.py;
}
language python;

The content of the example script is below

lab@vMX-1> file show /var/db/scripts/op/device_info.py 
 
from junos import Junos
from junos import Junos_Context
from jnpr.junos import Device   # PyEZ
import jcs
 
jdev = Device().open()
inv = jdev.rpc.get_chassis_inventory()
 
print "Model: %s" % inv.find('chassis/description').text
print "Serial number: %s" % inv.find('chassis/serial-number').text
 
jdev.close()

 

 

Best Regards,
PK

Juniper Ambassador, Juniper Networks Certified Instructor,
JNCIE-SEC #98, JNCIE-ENT #393, JNCIE-SP #2253
Twitter: @JuniperTrain
GitHub: https://github.com/pklimai
[Juniper Authorized Education & Support in Russia]
Highlighted
Junos

Re: Junos - python : operation not permitted

‎12-31-2019 03:33 PM

Hello, i see that you are using a usernamed "lab" what privilages does this user has ? 

Highlighted
Junos

Re: Junos - python : operation not permitted

‎12-31-2019 03:34 PM

did you run the tests with user root and if yes were the results same as seen with user lab ? 

Feedback