Using Census Bulk Geocoder with python requests library -
i experimenting census bulk geocode api (documentation: http://geocoding.geo.census.gov/geocoder/geocoding_services_api.pdf)
the following curl command works:
curl --form addressfile=@addresses.csv --form benchmark=9 http://geocoding.geo.census.gov/geocoder/locations/addressbatch --output geocoderesult.csv
but when attempt port python requests:
url = 'http://geocoding.geo.census.gov/geocoder/geographies/addressbatch' payload = {'benchmark':9} files = {'addressfile': ('addresses.csv', open('addresses.csv', 'rb'), 'text/csv')} r = requests.post(url, files=files, data = payload) print r.text
i apparently not sending formed request , receiving "there internal error" in response. idea doing wrong in forming request?
got it! turns out geographies request type required parameters locations type did not. working solution:
url = 'http://geocoding.geo.census.gov/geocoder/geographies/addressbatch' payload = {'benchmark':'public_ar_current','vintage':'acs2013_current'} files = {'addressfile': ('addresses.csv', open('addresses.csv', 'rb'), 'text/csv')} r = requests.post(url, files=files, data = payload) print r.text
Comments
Post a Comment