gpt4 book ai didi

Python paramiko 错误 "TypeError: ' NoneType' object is not iterable"only for a particular computer

转载 作者:太空宇宙 更新时间:2023-11-04 03:31:10 25 4
gpt4 key购买 nike

尝试使用 paramiko 连接到远程 Unix 服务器时出现错误:

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 包的笔记本电脑可能会出现什么问题。请帮忙。

最佳答案

根据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

关于Python paramiko 错误 "TypeError: ' NoneType' object is not iterable"only for a particular computer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31071960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com