From: Michael Orlitzky Date: Sun, 1 Jan 2017 22:06:51 +0000 (-0500) Subject: Catch and report HTTPExceptions in addition to HTTPErrors. X-Git-Tag: 0.0.5~2 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=e902576de37fc1d86edb35d852b3149fde55213e;p=untangle-https-backup.git Catch and report HTTPExceptions in addition to HTTPErrors. --- 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