Troubleshoot Junos PyEZ Connection Errors
Troubleshoot Refused Connection Errors
Problem
Description
When using Junos PyEZ to manage remote Junos devices, the code generates an error that the connection was refused. For example:
jnpr.junos.exception.ConnectRefusedError
Cause
NETCONF is not enabled on the device or the number of connections exceeds the limit.
The most likely cause for a refused connection error is that NETCONF over SSH is not enabled on the Junos device. To quickly test whether NETCONF is enabled, verify that the user account can successfully start a NETCONF session with the device.
[user@server]$ ssh user@R1.example.com -p 830 -s netconf
Solution
If NETCONF is not enabled on the Junos device, enable NETCONF.
[edit] user@R1# set system services netconf ssh user@R1# commit
If the number of NETCONF sessions exceeds the limit, increase the maximum number of permitted sessions up to 250. The default is 75.
[edit] user@R1# set system services netconf ssh connection-limit limit user@R1# commit
Troubleshoot Junos PyEZ Connection Errors in Onbox Event Scripts
Problem
Description
When using Junos PyEZ in an onbox Python event script, the code generates a ConnectError message referencing user "nobody". For example:
ConnectError(host: None, msg: user "nobody" does not have access privileges.)
Cause
To prevent the execution of unauthorized Python code, by default,
Junos devices execute Python event scripts using the access
privileges of the generic, unprivileged user and group
nobody.
Solution
To execute event scripts using the access privileges of a
specific user, you must configure the
python-script-user statement for
that event script and specify a user. The configured user
must have a local user account on the device.
[edit] user@host# set event-options event-script file filename python-script-user user user@host# commit
You cannot configure Python event scripts to execute with root access privileges.
For example:
[edit] user@host# set event-options event-script file bgp-neighbors.py python-script-user admin user@host# commit