DenisCarriere / geocoder

:earth_asia: Python Geocoder
http://geocoder.readthedocs.org
MIT License
1.61k stars 285 forks source link

Google Requires API KEY #384

Open akaszynski opened 5 years ago

akaszynski commented 5 years ago

Looks like google just started requiring an API key. A more informative error would be great when requesting from Google.

dk-WZFinTech commented 5 years ago

Actually status looks fine:

>>> g = geocoder.google('Zoo Hamburg')
>>> g.ok
False
>>> g.status_code
200
>>> g.response
<Response [200]>
>>> g.status
u'REQUEST_DENIED'

But I don't find any info how to handle with API_KEY - where should it be put to be include to calls?


Update

OK, I answer myself with this: https://geocoder.readthedocs.io/providers/Google.html#environment-variables

But It will be nice to have something like envs settings in package.

gordol commented 5 years ago

literally: geocoder.google(QUERY, key=KEYGOESHERE)

this is already supported, no?

https://github.com/DenisCarriere/geocoder/blob/master/geocoder/google.py#L192

FelixBuehler commented 5 years ago
In [2]: import os                                                                                                                               

In [3]: os.environ["GOOGLE_API_KEY"] = "MY_API_KEY"                                                                

In [4]: import geocoder                                                                                                                         

In [5]: g = geocoder.google('Mountain View, CA')                                                                                                

In [6]: g                                                                                                                                       
Out[6]: <[REQUEST_DENIED] Google - Geocode [empty]>

In [7]: g = geocoder.google('Mountain View, CA', key="MY_API_KEY")                                                 

In [8]: g                                                                                                                                       
Out[8]: <[REQUEST_DENIED] Google - Geocode [empty]>

This is not working for me. Neither the environmental option, nor via key parameter.

AnthonyFillionMaillet commented 5 years ago

GOOGLE_API_KEY = os.environ['GOOGLE_API_KEY']

Tested with Django, working well here

FelixBuehler commented 5 years ago

still not working for me. that's how it looks like for me:

import os
import geocoder

os.environ["GOOGLE_API_KEY"] = "xyz"       
GOOGLE_API_KEY = os.environ['GOOGLE_API_KEY']

g = geocoder.google('Mountain View, CA', key=GOOGLE_API_KEY)              
print(g)

<[REQUEST_DENIED] Google - Geocode [empty]>
froggie901 commented 4 years ago

Would be nice if these information was somewhere in the install guide, because otherwise the instal guide doesn't make sense.

andybak commented 4 years ago

I ended up here because I didn't find it in the docs. "Providers" is right down the bottom of the page and not in the sidebar TOC. I didn't even spot there were more docs beyond the initial page.

The docs should mention much higher up the page that api keys might be needed and provider specific info is available.

EDIT - oh and better error messages!

LuiCotias commented 4 years ago

still not working for me. that's how it looks like for me:

import os
import geocoder

os.environ["GOOGLE_API_KEY"] = "xyz"       
GOOGLE_API_KEY = os.environ['GOOGLE_API_KEY']

g = geocoder.google('Mountain View, CA', key=GOOGLE_API_KEY)              
print(g)

<[REQUEST_DENIED] Google - Geocode [empty]>

Maybe you need to enable billing on your google dev account.

israelins85 commented 2 years ago

I have same problem, but calling direct works. https://maps.googleapis.com/maps/api/geocode/json?address=21+RUA+JAIME+BENEVOLO+6050080+CENTRO+Fortaleza+CE+brasil&bounds=&components=&region=&language=&key=GOOGLE_API_KEY