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連接就行了