X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=bin%2Funtangle-https-backup;h=1f6a2db3fcf671c27176aeff71d01f0fd52912cd;hb=31baaa4a8ec5545be073bc6fc8ff3dd7a49d9707;hp=dab5c1807bb8e9c712c34d0a184df270f93a15e9;hpb=b76e936f471c7c0c31652056fde8555ab3b913f2;p=untangle-https-backup.git diff --git a/bin/untangle-https-backup b/bin/untangle-https-backup index dab5c18..1f6a2db 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 @@ -53,11 +54,21 @@ for section in config.sections(): # If it didn't work, but in a predictable way (some host is down), # then we report that error and keep going. 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: + # At least one sort of HTTPException (BadStatusLine) is not + # translated by urllib into an HTTPError, so we catch + # HTTPExceptions too. + tpl = '{:s}: HTTP exception {:s} from {:s}' + msg = tpl.format(u.name, repr(e), u.host) print(msg, file=stderr) status = EXIT_BACKUPS_FAILED