Cannot Open Connection to Juniper Switch: jnpr.junos.exception.ConnectAuthError: ConnectAuthError([SWITCH-NAME])

735 views
Skip to first unread message

bri...@seas.upenn.edu

unread,
Feb 3, 2017, 11:31:06 AM2/3/17
to Junos Python EZ

I am getting this error when trying to run a script that edits the junos config:

Traceback (most recent call last):

 File "edit-config.py", line 26, in <module>
   switch.open()
 File "/usr/lib/python2.7/site-packages/jnpr/junos/device.py", line 880, in open
   raise EzErrors.ConnectAuthError(self)
jnpr.junos.exception.ConnectAuthError: ConnectAuthError([SWITCH-NAME])

I know this error indicates that the username or password is incorrect. However, I have tried hardcoding known good credentials into the script and get the same error. I am able to ssh to the switch manually with these credentials outside of the script. Code pasted below. I've taken out any potentially identifiable info for privacy. I'd also like to note that I enabled netconf on the switch with 'set system services netconf ssh'. Any help would be greatly appreciated.

#!/usr/bin/python
 2  
 3 """edit-config.py: makes changes to the Junos config."""
 4  
 5 from jnpr.junos import Device
 6 from jnpr.junos.utils.config import Config
 7 import sys
 8  
 9 # promt user for login info
10 hostname = raw_input("Hostname: ")
11 user = raw_input("User: ")
12 password = raw_input("Password: ")
13  
14 # create a device object from login info above
15 switch = Device(hostname, user, password)
16  
17 # open a connection to the device object
18 # throw an error if unsuccessful
19 """
20 try:
21     switch.open()
22 except Exception as err:
23     print("Unable to connect to " + hostname + ".")
24     sys.exit(1)
25 """
26 switch.open()
27  
28 # get the config and lock it so no one else can make changes
29 cfg = Config(switch)
30 cfg.lock()
31  
32 # append to config
33 # in this case, adding an IP to firewall filter [FILTER-NAME]
34 cfg.load("set firewall family inet filter [FILTER-NAME] term 2-1 from source-address [IP-ADDRESS]", format="set", merge=True)
35  
36 # unlock config
37 cfg.unlock()
38  
39 # close connection to device
40 switch.close()

Nitin Kumar

unread,
Feb 3, 2017, 11:41:11 AM2/3/17
to bri...@seas.upenn.edu, Junos Python EZ
Can you please enable logging with debug level in your script. Share the log. 
ConnectAuthError([SWITCH-NAME])
Also can please help me if you edited above line to put switch-name under a list or it's coming from script. 

Thanks
Nitin Kr

Sent from mobile, please excuse my brevity 
--
You received this message because you are subscribed to the Google Groups "Junos Python EZ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to junos-python-...@googlegroups.com.
Visit this group at https://groups.google.com/group/junos-python-ez.
To view this discussion on the web visit https://groups.google.com/d/msgid/junos-python-ez/5326de1b-9cd7-4dc6-aa57-a59bdc8be278%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bri...@seas.upenn.edu

unread,
Feb 3, 2017, 3:28:29 PM2/3/17
to Junos Python EZ, bri...@seas.upenn.edu, nit...@juniper.net
Nitin,

Thanks for the response! I'm having some trouble with the logging. Please forgive me as i'm just a security guy, not a dedicated developer. I threw this in my script:

8 import logging                                                                                     
9                                                                                                       
10 logging.basicConfig(level=logging.DEBUG)                                                            
11 logger = logging.getLogger(__name__)

However, I'm not sure exactly how I use the logging object i've created to get the information you are asking for.

As for the error, it outputs ConnectAuthError(hostname), where hostname is whatever hostname is set to.

Stacy Smith

unread,
Feb 3, 2017, 5:21:44 PM2/3/17
to Junos Python EZ

On Friday, February 3, 2017 at 9:31:06 AM UTC-7, bri...@seas.upenn.edu wrote:
14 # create a device object from login info above 
15 switch = Device(hostname, user, password) 

PyEZ only supports passing the hostname as the first positional argument to Device(). It does not support any additional positional arguments. Additional arguments must be specified as keyword arguments.

You need to change line 15 to:
switch = Device(hostname, user=user, passwd=password) 

or even better:
switch = Device(host=hostname, user=user, passwd=password)

--Stacy

bri...@seas.upenn.edu

unread,
Feb 6, 2017, 10:40:30 AM2/6/17
to Junos Python EZ
Stacy, my script works after making the change. Thanks for your help!
Reply all
Reply to author
Forward
0 new messages