Oops, unhandled type 3 ('unimplemented'
'NoneType' object has no attribute 'open_session'
Authentication failed.
后两个加上 timeout参数就可以解决了。
但是第一个异常一直不行,最后想起异常的时候一直没有关闭连接,然后把ssh连接在异常的时候加上关闭连接就行了
def link_server(self):
""" 连接传输命令服务器"""
ip, user, pwd = self.get_msg()
print(self.ip + " " + self.user + " " + self.pwd)
print(f'正在连接服务器,服务器ip{self.ip}')
# 自动登录
#SSH_CLIENT.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
SSH_CLIENT.set_missing_host_key_policy(paramiko.AutoAddPolicy())
SSH_CLIENT.connect(hostname=self.ip,
port=SSH_PORT,
username=self.user,
password=self.pwd,
timeout=2,
) # 加上timeout参数
print('服务器连接成功!!!')
print('连接成功')
except Exception as e:
print('服务器连接失败,请检查ip地址,用户名与密码')
print(e)
print('服务器连接失败')
SSH_CLIENT.close() # 加上关闭ssh连接就行了