我的 python 代码遇到问题,基本上我建立了多个 SSH 连接。 我一直使用这种格式:
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")
但是这个异常让我走向了错误的方向,因为 file1 不是从之前的 try/ except/finally 下载的。
所以我想知道是否存在另一种方式来显示与 paramiko 错误相关的更多信息(而不是
except Exception e
)。
是的,可以显示回溯
import traceback
...
except Exception e:
print (e)
print(traceback.format_exc())
...