2015-06-26 80 views
2

在尝试使用paramiko我收到错误连接到远程Unix服务器:的Python的paramiko错误“类型错误:‘NoneType’对象不是可迭代”仅适用于特定的计算机

TypeError: 'NoneType' object is not iterable"

出人意料的是,当我尝试从具有相同服务器,用户名和密码的不同笔记本电脑运行相同的脚本,我可以连接到服务器并执行远程命令。

>>> import paramiko 
>>> ssh = paramiko.SSHClient() 
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
>>> ssh.connect(ftpipaddress,username ='akar',password ='change') 
Traceback (most recent call last): 
File "<interactive input>", line 1, in <module> 
TypeError: 'NoneType' object is not iterable 

完全不知道什么可能是具有安装在其相同的Python 2.7和paramiko包笔记本电脑的问题。请帮忙。

回答

2

根据documentation,connect方法不返回任何内容。就Python而言,这意味着,此方法返回None。您可能正在寻找exec_command方法:

exec_command(command, bufsize=-1, timeout=None, get_pty=False) 

Execute a command on the SSH server. A new Channel is opened and the requested command is executed. The command’s input and output streams are returned as Python file-like objects representing stdin, stdout, and stderr.

Parameters:

  • command (str) – the command to execute

  • bufsize (int) – interpreted the same way as by the built-in file() function in Python

  • timeout (int) – set command’s channel timeout. See Channel.settimeout.settimeout

Returns: the stdin, stdout, and stderr of the executing command, as a 3-tuple

Raises SSHException: if the server fails to execute the command

+0

我已经编辑了问题......这个问题时,我不会给标准输入,标准输出,标准错误 – user3565150

+0

嗯......你能不能请,将代码放到仍然出现一个文件并在Python下运行?它会产生完整的追溯? – soon

相关问题