1

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!

askedFeb 17, 2022 at 15:00
Jessica Garcia's user avatar
3
  • "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 AskCommentedFeb 17, 2022 at 16:31
  • I have updated the full error code, thank you for pointing this out.CommentedFeb 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 theaddress parameter 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 convertingaddresses to a string) would indeed likely return a400 Bad Request response from the API itself. Why not loop over each address instead..?CommentedFeb 17, 2022 at 23:44

0

Know someone who can answer? Share a link to thisquestion viaemail,Twitter, orFacebook.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.