Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get more info from try/except

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).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, can display the traceback of code executed

import traceback

...
except Exception e:
    print (e)
    print(traceback.format_exc())
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading