import requests
from bs4 import BeautifulSoup
-from requests.utils import quote
+from requests.utils import requote_uri
logger = logging.getLogger(__name__)
'5 SHELBERN DR, LINCROFT, NJ, 07738'
"""
- encoded_address = quote(address)
url = 'https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress'
- url += f'?address={encoded_address}'
+ url += f'?address={address}'
url += '&layers=all&benchmark=4&vintage=4'
+ url = requote_uri(url)
logger.debug('GET: %s', url)
r = requests.get(url)
if r.status_code != 200:
- logger.error(f'Unexpected response code {r.status_code}, wanted 200. Fail.')
+ logger.error('Unexpected response code %d, wanted 200. Fail.', r.status_code)
return None
else:
soup = BeautifulSoup(r.text, 'html.parser')
out = {}
for line in output.split('\n'):
if re.match(r'.*: *$', line):
- label = line[:-2].strip()
+ line = line.strip()
+ label = line[:-1]
logger.debug('Label is: "%s"', label)
else:
if label: