I am in need of some help at the moment with some research that I am working on in python. I cannot get this Geocoding API by google to work for some reason and I am not understanding the error code despite Googling that stuff.Note: I have a dataframe that I converted into a dictionary to pass into this documentation for the Geocoding API.
The code:
API_KEY = 'private' # appending all addresses in radius_0 to the list titled addresses addresses = [] for each_dict in final_dict: address = final_dict['Location'] addresses.append(address) print(addresses) # parameters params = { 'key': API_KEY, 'address': addresses } # following google documentation with the url provided for the API request base_url = 'https://maps.googleapis.com/maps/api/geocode/json?' # to see print(response) response = requests.get(base_url, params=params).json() # accessing the keys of the dictionary titled response response.keys() if response['status'] == 'OK': geometry = response['results'][0]['geometry'] lat = geometry['location']['lat'] lon = geometry['location']['lng'] print((lat, lon)) # Error Code: HTTPError Traceback (most recent call last)/var/folders/s6/zdp5jv2j74l4k3nty81q0wrm0000gn/T/ipykernel_40787/2892721893.py in <module> 25 26 response = requests.get(base_url, params=params)---> 27 response.raise_for_status() # raises exception when not a 2xx response 28 if response.status_code != 204: 29 return response.json()~/opt/anaconda3/lib/python3.9/site-packages/requests/models.py in raise_for_status(self) 951 952 if http_error_msg:--> 953 raise HTTPError(http_error_msg, response=self) 954 955 def close(self):HTTPError: 400 Client Error: Bad Request for url:Thank you very much and any help or tips are extremely appreciated!
- "I am not understanding the error code despite Googling that stuff" Any reason you haven't provided the full error text in the body of your question?How to Askesqew– esqew2022-02-17 16:31:31 +00:00CommentedFeb 17, 2022 at 16:31
- I have updated the full error code, thank you for pointing this out.Jessica Garcia– Jessica Garcia2022-02-17 23:38:56 +00:00CommentedFeb 17, 2022 at 23:38
- Thanks. Can you elaborate as to how you reached the conclusion that you should be able to pass a list object withmultiple addresses into the
addressparameter of this API? Can you point to the specific documentation item for which you are basing this implicit claim? Nothing my cursory research turns up points to the possibility of bulk-geocoding like this, and passing an incorrectly-formatted string (as a result of ostensibly implicitly convertingaddressesto a string) would indeed likely return a400 Bad Requestresponse from the API itself. Why not loop over each address instead..?esqew– esqew2022-02-17 23:44:29 +00:00CommentedFeb 17, 2022 at 23:44
Related questions
Related questions