关闭连接时出现python paramiko问题 [英] python paramiko Issue while closing the connection
问题描述
我刚刚尝试与 paramiko
建立 ssh 连接.一切看起来都很好,但在最后一步,当调用 close()
方法断开客户端连接时.
I have just been trying ssh connection with paramiko
.
Everything looks fine, but in the final step, when calling the close()
method to disconnect the client.
这是我的脚本:
#!/usr/bin/python
import paramiko
import os
ssh = paramiko.SSHClient()
private_key = os.path.expanduser('~/.ssh/id_dsa')
mkey = paramiko.DSSKey.from_private_key_file(private_key,password='JacquiKoala')
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('monitor', username='probert', pkey = mkey)
stdin, stdout, stderr = ssh.exec_command('whoami')
print stdout.readlines()
ssh.close
shell 挂了,我可以输入东西,没有任何结果,Ctrl+C 或 Ctrl+D 不要停止脚本或连接.除了关闭有点脏的外壳窗口之外,我别无他法.
The shell just hangs, I can type stuff, without any result, Ctrl+C or Ctrl+D don't stop the script nor the connection. I have no other way except closing the shell window which is kind of dirty.
我正在使用从源代码编译的 python 2.6.6
和 paramiko-1.7.4
运行 Ubuntu 10.10.
I am running Ubuntu 10.10 with python 2.6.6
and paramiko-1.7.4
compiled from sources.
我真的不知道会发生什么;close()
方法在执行后也作为打印blah"正确执行,没有错误消息,并且仍然连接,没有适当的方法来停止它.
I really don't know what happens; the close()
method is correctly executed as a print "blah" after is executed as well, no error message, and still connected without an appropriate way to stop it.
谢谢你帮助我:)
干杯;
菲利普
推荐答案
TL;DR:您没有调用该函数.使用 ssh.close()
而不是 ssh.close
TL;DR: You are not calling the function. Do so with ssh.close()
instead of ssh.close
ssh.close
是对该函数的引用.它告诉您有关该函数的信息,它不会调用该函数.下面是一个例子:
ssh.close
is a reference to that function. It tells you about the function, it does not call the function. Here is an example:
def a():
return 6
a
> <function a at 0x108f71aa0>
a()
> 6
这篇关于关闭连接时出现python paramiko问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!