Error Handling Paramiko (Python)

5

Hello,

I am putting together a script where the user will authenticate to an equipment, if everything goes right the code continues or it shows an error message. I am using the Paramiko library to do the session with the equipment, the connection is ok and it returns the message that I want when the connection fails, but another error appears soon after.

MY CODE:

username = raw_input("Username:")
password = getpass.getpass("Password: ")

remote_conn_pre = paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())

try:
    remote_conn_pre.connect('1.111.111.111', username=username, password=password)
except paramiko.ssh_exception.AuthenticationException:
    print ("Erro de login.")

ERROR FOLLOWS:

  File "run.py", line 67, in <module>
    remote_conn_pre.connect(ip, username=username, password=password)
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 380, in connect
    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 603, in _auth
    raise saved_exception
paramiko.ssh_exception.AuthenticationException: Authentication failed.

I do not know how to use the paramiko.ssh_exception.AuthenticationException right, can anyone help me?

And one more question, do I have to do it if it gives an error, does it return to the user to enter the username / password again?

Sorry, I'm kind of new to programming and Python, so do not worry. Many thanks!

    
asked by anonymous 12.07.2016 / 19:16

0 answers