我正在使用带有Python的Google Places API来构建聊天机器人应用程序以建议附近的地方。
我指的是以下链接: https://github.com/slimkrazy/python-google-places
我正在做这样的事情:
from googleplaces import GooglePlaces, types, lang
API_KEY = ''
google_places = GooglePlaces(API_KEY)
query_result = google_places.nearby_search(
location='Mumbai', keyword='Restaurants',
radius=1000, types=[types.TYPE_RESTAURANT])
if query_result.has_attributions:
print query_result.html_attributions
for place in query_result.places:
print place.name
print place.geo_location
print place.place_id
它在链接本身中给出。但是,我一直收到以下错误:
Traceback (most recent call last):
File "run.py", line 9, in <module>
radius=1000, types=[types.TYPE_RESTAURANT])
File "/home/neetu/Desktop/python-google-places/googleplaces/__init__.py", line 281, in nearby_search
lat_lng_str = self._generate_lat_lng_string(lat_lng, location)
File "/home/neetu/Desktop/python-google-places/googleplaces/__init__.py", line 593, in _generate_lat_lng_string
'lat_lng must be a dict with the keys, \'lat\' and \'lng\'. Cause: %s' % str(e))
ValueError: lat_lng must be a dict with the keys, 'lat' and 'lng'. Cause: Request to URL https://maps.googleapis.com/maps/api/geocode/json?sensor=false&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI&address=Mumbai failed with response code: REQUEST_DENIED
非常欢迎任何帮助:)
答案 0 :(得分:1)
根据文件: https://github.com/slimkrazy/python-google-places/blob/master/googleplaces/init.py:
您应该能够提供位置而不是lat_lng对,但您可以尝试提供lat_lng而不是位置。
尝试删除:
location="Mumbai"
并添加
lat_lng={'lat:19.148320, 'lng':72.888794}
在深入研究代码后,我理解了错误。 你得到的错误是:
ValueError:lat_lng必须是带有键的字典,&#39; lat&#39;并且&#39; lng&#39;。原因:&gt;请求网址https://maps.googleapis.com/maps/api/geocode/json?&gt; sensor = false&amp; key = AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI&amp; address = Mumbai failed&gt; with response code:REQUEST_DENIED
它的含义是,它试图通过谷歌来获取&#34;孟买&#34;的lat_lng对,但请求失败,因为它被拒绝了。使用Google提供的有效API密钥,它应该有效。