From e902576de37fc1d86edb35d852b3149fde55213e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 1 Jan 2017 17:06:51 -0500 Subject: [PATCH] Catch and report HTTPExceptions in addition to HTTPErrors. --- bin/untangle-https-backup | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/untangle-https-backup b/bin/untangle-https-backup index dab5c18..69e46ba 100755 --- a/bin/untangle-https-backup +++ b/bin/untangle-https-backup @@ -5,6 +5,7 @@ Back up Untangle configurations via the web admin UI. from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser import configparser +from http.client import HTTPException from os import chmod from urllib.error import HTTPError, URLError from sys import stderr @@ -51,13 +52,22 @@ for section in config.sections(): chmod(filename, 0o600) # If it didn't work, but in a predictable way (some host is down), - # then we report that error and keep going. + # then we report that error and keep going. At least one sort of + # HTTPException (BadStatusLine) is not translated by urllib into + # an HTTPError, so we catch HTTPExceptions too. except URLError as e: - msg = u.name + ': ' + str(e.reason) + ' from ' + u.host + tpl = '{:s}: {:s} from {:s}' + msg = tpl.format(u.name, str(e.reason), u.host) print(msg, file=stderr) status = EXIT_BACKUPS_FAILED except HTTPError as e: - msg = u.name + ': ' + 'HTTP error ' + str(e.code) + ' from ' + u.host + tpl = '{:s}: HTTP error {:s} from {:s}' + msg = tpl.format(u.name, str(e.code), u.host) + print(msg, file=stderr) + status = EXIT_BACKUPS_FAILED + except HTTPException as e: + tpl = '{:s}: HTTP exception {:s} from {:s}' + msg = tpl.format(u.name, repr(e), u.host) print(msg, file=stderr) status = EXIT_BACKUPS_FAILED -- 2.43.2