From 4b617c7e0e2ea9a83a2c7d98a18e2433c7c92a1a Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sat, 30 Apr 2022 17:42:14 -0700 Subject: [PATCH] Better logging + cleanup. --- geocode.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/geocode.py b/geocode.py index 176487a..15ffff0 100644 --- a/geocode.py +++ b/geocode.py @@ -7,6 +7,7 @@ https://www2.census.gov/geo/pdfs/maps-data/data/Census_Geocoder_User_Guide.pdf https://geocoding.geo.census.gov/geocoder/Geocoding_Services_API.pdf """ +import json import logging from typing import Any, Dict, List, Optional @@ -43,9 +44,10 @@ def geocode_address(address: str) -> Optional[Dict[str, Any]]: return None if r.status_code != 200: + logger.debug(r.text) logger.error('Unexpected response code %d, wanted 200. Fail.', r.status_code) return None - # print(json.dumps(r.json(), indent=4, sort_keys=True)) + logger.debug('Response: %s', json.dumps(r.json(), indent=4, sort_keys=True)) return r.json() @@ -86,10 +88,12 @@ def batch_geocode_addresses(addresses: List[str]): except Exception as e: logger.exception(e) return None + if r.status_code != 200: - print(r.text) + logger.debug(r.text) logger.error('Unexpected response code %d, wanted 200. Fail.', r.status_code) return None + logger.debug('Response: %s', r.text) for line in r.text.split('\n'): line = line.strip() if len(line) > 0: -- 2.47.1