我尝试在服务器上执行并行ssh。在这样做的时候,我得到了“TypeError:'NoneType”object is not iterable“这个错误。请帮忙。在
我的剧本在下面
from pssh import ParallelSSHClient
from pssh.exceptions import AuthenticationException, UnknownHostException, ConnectionErrorException
def parallelsshjob():
client = ParallelSSHClient(['10.84.226.72','10.84.226.74'], user = 'root', password = 'XXX')
try:
output = client.run_command('racadm getsvctag', sudo=True)
print output
except (AuthenticationException, UnknownHostException, ConnectionErrorException):
pass
#print output
if __name__ == '__main__':
parallelsshjob()
回溯如下
^{pr2}$帮助我解决这个问题,并建议我在这个脚本中使用ssh代理。提前谢谢。在
通过在我的笔记本电脑上阅读代码和调试,我相信问题是您没有一个名为
~/.ssh/config
的文件。似乎parallel-ssh
依赖于OpenSSH配置,这是丢失该文件时出现的错误。在read_openssh_config
此处不返回:https://github.com/pkittenis/parallel-ssh/blob/master/pssh/utils.py#L79反过来,
SSHClient.__init__
在试图解压缩它期望接收的值时爆炸:https://github.com/pkittenis/parallel-ssh/blob/master/pssh/ssh_client.py#L97。在修复的方法大概是让某种OpenSSH配置文件就位,但很抱歉,我对此一无所知。在
编辑
在清理了
parallel-ssh
的一些异常处理之后,下面是一个更好的错误堆栈跟踪:这个was seemingly a regression in the ^{} version of the library 现在在0.92.1中解析。以前的版本也可以。OpenSSH config不应该是依赖项。在
要回答您的SSH代理问题,如果有一个正在运行并在用户会话中启用,它将自动使用。如果希望以编程方式提供私钥,可以执行以下操作
也可以通过编程方式为代理提供多个密钥,如下所示
^{pr2}$See documentation获取更多示例。在
相关问题 更多 >
编程相关推荐