分类
devops

python3报错TypeError: ‘NoneType’ object is not callable

报错信息

Exception ignored in: <function BufferedFile.__del__ at 0x7f3bb8736730>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/paramiko/file.py", line 66, in __del__
  File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 1392, in close
  File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 991, in shutdown_write
  File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 963, in shutdown
  File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 1246, in _send_eof
  File "/usr/local/lib/python3.7/dist-packages/paramiko/message.py", line 232, in add_int
TypeError: 'NoneType' object is not callable

报错代码

#!/usr/bin/python3
import os
import socket
import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='192.168.1.11', port=22, username='root', password='123456')
stdin, stdout, stderr = ssh.exec_command('ls -l')

正确代码

#!/usr/bin/python3
import os
import socket
import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='192.168.1.11', port=22, username='root', password='123456')
stdin, stdout, stderr = ssh.exec_command('ls -l')
result = stdout.read()
if not result:
    result = stderr.read()
ssh.close()
print(result.decode())

结论