Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

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

localhost >> a(server) ssh >> b

like image 425
ForeverNews Avatar asked Feb 03 '20 10:02

ForeverNews


3 Answers

Just close stdin

stdin, stdout, stderr = ssh.exec_command(commands)
stdin.close()
like image 182
Sanan Guliyev Avatar answered Oct 18 '22 21:10

Sanan Guliyev


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

like image 42
Jesus Briceño Avatar answered Oct 18 '22 21:10

Jesus Briceño


add the below:

if __name__ == "__main__":
    main()

then put your code in the main() def

like image 5
SMustapha Avatar answered Oct 18 '22 21:10

SMustapha