I wrote a simple program to create an SSH connection through paramiko, and then executed a simple command. But it always throws an exception error: -
Exception in Thread-1 thread (most likely when shutdown is interpreted): Traceback (last last call): File "/usr/lib/python2.7/threading.py", line 530, in __bootstrap_inner
File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 1574, at startup: object "NoneType" has no attribute 'error'
The program I wrote is as follows: -
class Session: def __init__(self, ipaddr, username, password): self.ipaddr = ipaddr self.username = username self.password = password self.connect() def connect(self): try: time.sleep(1) self.ssh = paramiko.SSHClient() self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: self.ssh.connect(self.ipaddr, username=self.username, password=self.password) time.sleep(2) except socket.error, e: print e self.ssh.close() sys.exit() except Exception, e: print e def executeCmd(self, cmd): data = "" try: stdin, stdout, stderr = self.ssh.exec_command(cmd) data = stdout.read() except SSHException, e: print "Error: ", e errorMsg = "Error: %s" %traceback.format_exc() print errorMsg return data def __del__(self): self.ssh.close()
How to resolve this exception? Please, help.
thanks
Ageek source share