From 1ba638df002f5b7cefc5c30623e7dbb17f4285bf Mon Sep 17 00:00:00 2001 From: thurask Date: Thu, 7 Sep 2017 12:47:13 -0400 Subject: [PATCH] clean up network error messages --- tclcheck_all.py | 5 ++++- tcllib.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tclcheck_all.py b/tclcheck_all.py index 536603b..5bf25d2 100644 --- a/tclcheck_all.py +++ b/tclcheck_all.py @@ -5,7 +5,7 @@ import tcllib import sys -from requests.exceptions import RequestException +from requests.exceptions import RequestException, Timeout fc = tcllib.FotaCheck() fc.serid = "3531510" @@ -28,6 +28,9 @@ for prdline in prds: check_xml = fc.do_check() curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml) print("{}: {} {} ({})".format(prd, tv, fhash, model)) + except Timeout as e: + print("{} failed. (Connection timed out.)".format(prd)) + continue except (SystemExit, RequestException) as e: print("{} failed. ({})".format(prd, str(e))) continue diff --git a/tcllib.py b/tcllib.py index a9b6838..22ad245 100644 --- a/tcllib.py +++ b/tcllib.py @@ -87,6 +87,8 @@ class FotaCheck: return req.text elif req.status_code == 204: raise requests.exceptions.HTTPError("No update available.", response=req) + elif req.status_code in (500, 503): + raise requests.exceptions.HTTPError("Server busy, try again later.", response=req) else: req.raise_for_status() raise requests.exceptions.HTTPError("HTTP {}.".format(req.status_code), response=req)