paramiko AttributeError: 'NoneType' object has no attribute 'time'

报错信息:

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

添加:stdin.close()

复制代码
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import paramiko
 
ssh= paramiko.SSHClient()#创建SSH对象
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())#允许连接不在know_hosts文件中的主机
ssh.connect(hostname='192.168.2.1', port=22, username='root', password='12345678')#连接服务器
 
stdin, stdout, stderr= ssh.exec_command('pwd')#执行命令并获取命令结果
stdin.close()
#stdin为输入的命令
#stdout为命令返回的结果
#stderr为命令错误时返回的结果
res, err= stdout.read(), stderr.read()
result= res if res else err
print(result)
ssh.close()#关闭连接
复制代码

更多改法:

https://stackoverflow.com/questions/60037299/attributeerror-nonetype-object-has-no-attribute-time-paramiko

posted @   船长博客  阅读(1400)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2017-07-16 Tkinter开发第一个桌面程序HelloWorld
永远相信美好的事情即将发生!
点击右上角即可分享
微信分享提示