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)
(不要忘记导入时间)
这似乎增加了更多的时间来处理命令
关于python - 属性错误 : 'NoneType' object has no attribute 'time' paramiko,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60037299/