how to get more info from try/except

63 Views Asked by At

I'm having problems with my code in python where basically I make several SSH connection. I'm always using this format:

try:
 ssh = paramiko.SSHClient()
 ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
 ssh.connect(IP, username=USER_GW, password=PSW_GW,look_for_keys=False) 
 stdin, stdout, stderr=ssh.exec_command(command, timeout=60)
 output=stdout.read().decode('ascii').strip("\n")         
except Exception e:
 print (e)
finally:
    ssh.close()
    stdin.close()
    stdout.close()
    stderr.close()

the error I'm getting is

Exception in Tkinter callback
Traceback (most recent call last)
os.replace(local_folder+'/file1', local_folder+"/file2")

but this exception is driving me in a wrong direction since file1 is not downloaded from the previous try/except/finally.

So I'm wondering if exist another way to show more information related to the paramiko error (instead of except Exception e).

1

There are 1 best solutions below

0
Wonka On BEST ANSWER

Yes, can display the traceback of code executed

import traceback

...
except Exception e:
    print (e)
    print(traceback.format_exc())
...