python ssh连接问题

时间:2010-11-29 13:49:39

标签: python ssh

我试过这段代码:

 import paramiko
 ssh = paramiko.SSHClient()
 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 ssh.connect('192.168.0.222', username='sshuser', password='pass')
 stdin, stdout, stderr = ssh.exec_command("pwd")    
 stdout.readlines()

和ssh连接有效,但是一旦我使用:

 stdin, stdout, stderr = ssh.exec_command("pwd")

我收到此错误消息:

  Exception in thread Thread-1 (most likely raised during interpreter shutdown)

如何才能执行“pwd”命令并获取输出? 谢谢!

1 个答案:

答案 0 :(得分:0)

try:
    stdin, stdout, stderr = ssh.exec_command("pwd")
except SSHException:
    ssh.close()

这会让它不会像那样崩溃,但不能解决你的问题。确保您可以连接常规ssh客户端并运行pwd。然后确保您的登录凭据正确无误。

相关问题