paramiko报错

错误信息:


Exception ignored in: 
Traceback (most recent call last):
  File "/Users/jerrylin/.conda/envs/pythonProject/lib/python3.8/site-packages/paramiko/file.py", line 66, in __del__
  File "/Users/jerrylin/.conda/envs/pythonProject/lib/python3.8/site-packages/paramiko/channel.py", line 1392, in close
  File "/Users/jerrylin/.conda/envs/pythonProject/lib/python3.8/site-packages/paramiko/channel.py", line 991, in shutdown_write
  File "/Users/jerrylin/.conda/envs/pythonProject/lib/python3.8/site-packages/paramiko/channel.py", line 967, in shutdown
  File "/Users/jerrylin/.conda/envs/pythonProject/lib/python3.8/site-packages/paramiko/transport.py", line 1846, in _send_user_message
AttributeError: 'NoneType' object has no attribute 'time'

程序代码:

import paramiko
import sys
import time
# 实例化SSHClient
client = paramiko.SSHClient()

# 自动添加策略,保存服务器的主机名和密钥信息,如果不添加,那么不再本地know_hosts文件中记录的主机将无法连接
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# 连接SSH服务端,以用户名和密码进行认证
client.connect()

# 打开一个Channel并执行命令
stdin, stdout, stderr = client.exec_command('ls data/data_target')  # stdout 为正确输出,stderr为错误输出,同时是有1个变量有值

# 打印执行结果
print(stdout.read().decode('utf-8'))

# 关闭SSHClient
client.close()

解决方案:

报错出现的原因是因为输出打印跟程序执行的close相互冲突,只需要在close之前添加一个time.sleep(1)就可以了

你可能感兴趣的:(python,python,深度学习,开发语言)