From 6fd34b009eec9cda18f1bdd9d8184b7a317a156d Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Fri, 29 Apr 2022 11:26:25 -0700 Subject: [PATCH] Handle census site unavailability w/o throwing. --- geocode.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/geocode.py b/geocode.py index 0a020d5..428eb58 100644 --- a/geocode.py +++ b/geocode.py @@ -35,7 +35,12 @@ def geocode_address(address: str) -> Optional[Dict[str, Any]]: url += '&layers=all&benchmark=4&vintage=4' url = requote_uri(url) logger.debug('GET: %s', url) - r = requests.get(url) + try: + r = requests.get(url) + except Exception as e: + logger.exception(e) + return None + if r.status_code != 200: logger.error('Unexpected response code %d, wanted 200. Fail.', r.status_code) return None -- 2.47.1