python连接到ssh一个现有的连接被远程主机强行关闭

问题描述:

当我尝试连接到我的服务器时

When I try connecting to my server

class ConnectToServer():

    def connect_to_vps(self):
        port = 22
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(self.IP, port=port, username="root", password="123", timeout=3)
        ssh.close()
scanner = ConnectToServer()
scanner.connect_to_ssh()

我收到这个错误,

paramiko.ssh_exception.SSHException:读取 SSH 协议横幅时出错[WinError 10054] 远程主机强行关闭了现有连接

paramiko.ssh_exception.SSHException: Error reading SSH protocol banner[WinError 10054] An existing connection was forcibly closed by the remote host

这种情况有时会发生

您正在 ssh.close() 处关闭函数内部的连接,这不是问题吗?

You are closing your connection inside your function at ssh.close(), isn't it the problem?