Fix crash on empty answer to the unknown host key prompt

An empty answer raised IndexError, and running without a terminal
(e.g. from cron) raised EOFError. Treat both as "no", and log why the
connection was aborted.
This commit is contained in:
Fuxino
2026-10-08 20:34:02 +02:00
parent 1dca989310
commit 9298f4232c
+9 -3
View File
@@ -375,12 +375,18 @@ class Backup:
return ssh return ssh
except UserWarning: except UserWarning:
k = input( try:
f'Unknown key for host {self.ssh_host}. Continue anyway? (Y/N) ') k = input(
f'Unknown key for host {self.ssh_host}. Continue anyway? (Y/N) ')
except EOFError:
# No terminal available (e.g. cron or systemd)
k = ''
if k[0].upper() == 'Y': if k.strip().upper().startswith('Y'):
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
else: else:
logger.critical('Unknown host key for %s. Connection aborted', self.ssh_host)
return None return None
except paramiko.BadHostKeyException as e: except paramiko.BadHostKeyException as e:
logger.critical('Can\'t connect to the server.') logger.critical('Can\'t connect to the server.')