Skip to content

Commit 3374024

Browse files
committed
better authentication failure handling
1 parent 92540a8 commit 3374024

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

soloutils/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ def _connect(ip, await=True, silent=False):
2929
socket.setdefaulttimeout(5)
3030
message = silent
3131
start = time.time()
32+
tryCount = 0
3233
while True:
34+
35+
if (tryCount >= 5):
36+
print 'error: unable to connect after {} attempts, giving up.'.format(tryCount)
37+
sys.exit(1)
38+
39+
tryCount = tryCount + 1
40+
3341
try:
3442
client.connect(ip, username='root', password='TjSDBkAu', timeout=5)
3543
except paramiko.BadHostKeyException:
@@ -39,15 +47,18 @@ def _connect(ip, await=True, silent=False):
3947
print ''
4048
print 'and try again'
4149
sys.exit(1)
50+
except paramiko.AuthenticationException as e:
51+
print 'ssh authentication error'
52+
raise e
4253
except Exception as e:
4354
if not await:
4455
raise e
45-
if not message and time.time() - start > 5:
56+
if not message and time.time() - start > 2:
4657
message = True
4758
print '(note: ensure you are connected to Solo\'s wifi network.)'
4859
client.close()
60+
time.sleep(1)
4961
continue
50-
time.sleep(1)
5162
break
5263
socket.setdefaulttimeout(None)
5364

0 commit comments

Comments
 (0)