简体   繁体   English

AttributeError: 'NoneType' 对象没有属性 'time' paramiko

[英]AttributeError: 'NoneType' object has no attribute 'time' 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()

Why have sometime will AttributeError: 'NoneType' object has no attribute 'time' in Python3.8 and sometime need wait long time show as result(or how can i see process)为什么有时会出现AttributeError: 'NoneType' object has no attribute 'time'在 Python3.8 中AttributeError: 'NoneType' object has no attribute 'time'有时需要等待很长时间才能显示结果(或者我怎么能看到进程)

Error code:错误代码:

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'

Advance进步

how can i use paramiko double ssh我如何使用 paramiko 双 ssh

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

Maybe you can try something like this:也许你可以尝试这样的事情:

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

(don't forget to import time) (不要忘记导入时间)

This seems to add more time to process the command这似乎增加了更多的时间来处理命令

add the below:添加以下内容:

if __name__ == "__main__":
    main()

then put your code in the main() def然后把你的代码放在 main() def

It's the bug opened on https://github.com/paramiko/paramiko/issues/1617 .这是在https://github.com/paramiko/paramiko/issues/1617 上打开的错误。 As @NobodyNada said adding a time.sleep(5) is a workaround.正如@NobodyNada 所说,添加 time.sleep(5) 是一种解决方法。

Just close stdin只需关闭stdin

stdin, stdout, stderr = ssh.exec_command(commands)
stdin.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 paramiko频道AttributeError:&#39;NoneType&#39;对象没有属性&#39;recv&#39; - paramiko channel AttributeError: 'NoneType' object has no attribute 'recv' AttributeError: &#39;NoneType&#39; 对象没有属性 - AttributeError: 'NoneType' object has no attribute AttributeError:“ NoneType”对象没有属性“ a” - AttributeError: 'NoneType' object has no attribute 'a' AttributeError : &#39;NoneType&#39; 对象没有属性 &#39;_meta&#39; - AttributeError : 'NoneType' object has no attribute '_meta' AttributeError:“ NoneType”对象没有属性“ dtype” - AttributeError: 'NoneType' object has no attribute 'dtype' AttributeError:“ NoneType”对象没有属性“ encode” - AttributeError: 'NoneType' object has no attribute 'encode' attributeError: &#39;NoneType&#39; 对象没有属性 &#39;end&#39; - attributeError: 'NoneType' object has no attribute 'end' AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;index&#39; - AttributeError: 'NoneType' object has no attribute 'index' AttributeError:“ NoneType”对象没有属性“ group” {for instagram} - AttributeError: 'NoneType' object has no attribute ‘group’ {for instagram} AttributeError: &#39;Nonetype&#39; 对象没有属性 &#39;enter&#39; python - AttributeError: 'Nonetype' object has no attribute 'enter' python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM