首页 > 解决方案 > AttributeError:“NoneType”对象没有属性“时间”paramiko

问题描述

import paramiko

key = paramiko.RSAKey.from_private_key_file("abc.pem")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("connecting")
ssh.connect(hostname="1.1.1.1", username="abc", pkey=key)
print("connected")
commands = "ip a"
stdin, stdout, stderr = ssh.exec_command(commands)
print(stdout.read())
print(stderr.read())
print(stdin.read())
ssh.close()

为什么有时会AttributeError: 'NoneType' object has no attribute 'time'在 Python3.8 中有时需要等待很长时间才能显示结果(或者我如何才能看到过程)

错误代码:

Exception ignored in: <function BufferedFile.__del__ at 0x108271ee0>
Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/paramiko/file.py", line 66, in __del__
  File "/venv/lib/python3.8/site-packages/paramiko/channel.py", line 1392, in close
  File "/venv/lib/python3.8/site-packages/paramiko/channel.py", line 991, in shutdown_write
  File "/venv/lib/python3.8/site-packages/paramiko/channel.py", line 967, in shutdown
  File "/venv/lib/python3.8/site-packages/paramiko/transport.py", line 1846, in _send_user_message
AttributeError: 'NoneType' object has no attribute 'time'

进步

我如何使用 paramiko 双 ssh

本地主机 >> a(服务器) ssh >> b

标签: pythonlinuxmacospython-3.8

解决方案


也许你可以尝试这样的事情:

stdin, stdout, stderr = ssh.exec_command(commands)
time.sleep(5)

(不要忘记导入时间)

这似乎增加了处理命令的时间


推荐阅读