开发者

python ssh connection problem

I tried this code:

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

and the ssh connection works, but as soon as I use:

 stdin, stdout, stderr = ssh.exec_co开发者_开发问答mmand("pwd")

I get this error message:

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

How can I just do the "pwd" command and get the output? Thanks!


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

That will keep it from crashing like that, but won't fix your problem. Make sure you can connect with a regular ssh client and run pwd. Then make sure your login credentials are correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜