Only turn warnings into errors where needed

warnings.filterwarnings('error') applied to the whole program, so
any warning raised by a library (e.g. a DeprecationWarning) would
crash it. Limit it to the ssh connection (unknown host key) and
the password prompt (no terminal available).
This commit is contained in:
Fuxino
2026-10-08 17:50:47 +02:00
parent e2d8897a45
commit 578d992a19
+7 -2
View File
@@ -37,8 +37,6 @@ from glob import glob
from dotenv import load_dotenv
warnings.filterwarnings('error')
try:
import paramiko
from paramiko import RSAKey, Ed25519Key, ECDSAKey, DSSKey
@@ -346,6 +344,9 @@ class Backup:
ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
# WarningPolicy emits a UserWarning for unknown host keys
with warnings.catch_warnings():
warnings.simplefilter('error', UserWarning)
ssh.connect(self.ssh_host, username=self.ssh_user)
return ssh
@@ -374,8 +375,12 @@ class Backup:
if self.ssh_keyfile is None:
try:
# Fail instead of reading the password with echo if no terminal is available
with warnings.catch_warnings():
warnings.simplefilter('error', GetPassWarning)
password = getpass(
f'{self.ssh_user}@{self.ssh_host}\'s password: ')
ssh.connect(self.ssh_host, username=self.ssh_user,
password=password)