From 9298f4232c1a6528f585c875342765bd2a2ac2c6 Mon Sep 17 00:00:00 2001 From: Fuxino Date: Thu, 8 Oct 2026 20:34:02 +0200 Subject: [PATCH] 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. --- simple_backup/simple_backup.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index 78a56be..f996878 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -375,12 +375,18 @@ class Backup: return ssh except UserWarning: - k = input( - f'Unknown key for host {self.ssh_host}. Continue anyway? (Y/N) ') + try: + 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()) else: + logger.critical('Unknown host key for %s. Connection aborted', self.ssh_host) + return None except paramiko.BadHostKeyException as e: logger.critical('Can\'t connect to the server.')