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
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