Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python geocoder REQUEST DENIED even with API key?

I signed up for a google API key to geocode addresses. I'm attempting to use Python's geocoder.

g = geocoder.google('Mountain View, CA', key='puting my key here')

However, it's still giving me:

<[REQUEST_DENIED] Google - Geocode [empty]>

What's going on here?

like image 609
DiamondJoe12 Avatar asked Sep 02 '25 07:09

DiamondJoe12


2 Answers

From the error message, I thought that Geocoding API might not be enabled at API console for the project retrieved the API key. Please confirm this. When the script is run after Geocoding API was enabled, the following response is returned.

<[OK] Google - Geocode [###]>

Note:

  • If you know the project ID, you can open the page for enabling the API at
    • https://console.cloud.google.com/apis/library/geocoding-backend.googleapis.com?project=project-id-#####
  • About pricing, please check https://cloud.google.com/maps-platform/pricing/.

References:

  • Google Maps Platform

If this was not useful for your situation, I apologize.

like image 62
Tanaike Avatar answered Sep 04 '25 20:09

Tanaike


You can get more information about the error by attempting to load your request in a browser. You can get the URL with g.url in the below example:

>>> import geocoder
>>> g = geocoder.google('Mountain View, CA', key='puting my key here')
>>> g.ok
False
>>> g
<[REQUEST_DENIED] Google - Geocode [empty]>
>>> g.url
'https://maps.googleapis.com/maps/api/geocode/json?address=Mountain+View%2C+CA&bounds=&components=&region=&language=&key=puting%20my%20key%20here'

When I copied that result into a browser window it was clear:

{
   "error_message" : "You must enable Billing on the Google Cloud Project at https://console.cloud.google.com/project/_/billing/enable Learn more at https://developers.google.com/maps/gmp-get-started",
   "results" : [],
   "status" : "REQUEST_DENIED"
}

In my case, @Tanaike was right: even though I recall enabling the new API key, I had not enabled 'billing' on my Google Cloud Project (https://console.cloud.google.com/project/_/billing/enable).

like image 34
Ryan Avatar answered Sep 04 '25 19:09

Ryan