I have a code where im looping through hosts list and appending connections to connections list, if there is a connection error, i want to skip that and continue with the next host in the hosts list.
Heres what i have now:
def do_connect(self):
"""Connect to all hosts in the hosts list"""
for host in self.hosts:
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host['ip'], port=int(host['port']), username=host['user'], timeout=2)
except:
pass
#client.connect(host['ip'], port=int(host['port']), username=host['user'], password=host['passwd'])
finally:
if paramiko.SSHException():
pass
else:
self.connections.append(client)
This does not work properly, if connection fails it just loops the same host again and again forever, till it establishes connection, how do i fix this?
continue.