I wrote a simple program to create an SSH Connection through paramiko and then execute a simple command. But it always throws an Exception error:-
Exception in thread Thread-1 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 530, in __bootstrap_inner
File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 1574, in run : 'NoneType' object has no attribute 'error'
The program that 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