python - 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
解决方案
也许你可以尝试这样的事情:
stdin, stdout, stderr = ssh.exec_command(commands)
time.sleep(5)
(不要忘记导入时间)
这似乎增加了处理命令的时间
推荐阅读
- mercurial - 无法提交与丢失文件的合并
- python - 调整 Kivy 滚动视图标签的大小
- excel - VBA:创建数据透视表
- excel - 如何计算具有多个范围的数字范围之间的每个值?
- google-apps-script - Google Forms Add-On - 安装插件后初始加载时菜单项未出现
- sql - 如何在 SQL 中计算百分比
- c# - 在文本框中输入相同的文本/字符串时如何获得另一个输出?
- javascript - Fabric.js:如何在组变大时防止文本模糊
- android-things - 有什么方法可以识别连接到覆盆子的多个 USB-uart 设备?
- mysql - 如何将带有西班牙字符(á、é、í、ó、ú、ñ)的 CSV 文件 utf-8 导入到 phpmyadmin 中的表格中