"SSHException" "ParallelSSHClien读取SSH协议横幅出错"

2024-04-19 07:53:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用ParallelSSHClient连接到多个服务器。 当我运行Python函数时,它运行得非常好。 然而,当我从Robot框架中的测试用例调用函数时,我得到了以下错误。在

SSHException: Error reading SSH protocol banner('This operation would block forever', )

我使用的Python函数是:

from pssh.pssh_client import ParallelSSHClient
from pssh.utils import load_private_key
from robot.libraries.BuiltIn import BuiltIn
def check101():
    pkey = load_private_key('/root/test.pem')
    hosts = ['2.2.2.2', '1.1.1.1']
    client = ParallelSSHClient(hosts, pkey=pkey)

    try: 
            output = client.run_command("<command>")
    except (AuthenticationException):
            print 'Error'
    node=0
    for host in output:
            for line in output[host].stdout:
                    node=node+1
                    if (int(line)>0):
                            return node
                            break
    return -1

Tags: key函数fromimportclientnodeoutputload