当我运行这段代码时,我的spyder终端没有完成,在点击enter几次之后,我得到了以下错误消息:
{‘目的地_地址’:[],'error_message':‘您必须使用一个API密钥来验证每个对Google平台API的请求。
这是我的密码:
def scrape_gmaps_data():
#import required libraries
import requests, json
#enter your api key here
api_key = 'I tried with my actual API key'
#take source as input
source = input()
#take destination as input
dest = input()
#url variable store url
url = 'https://maps.googleapis.com/maps/api/distancematrix/json?'
#get method of requests module
#return response object
r = requests.get(url + 'origins = ' + source + '&destinations = ' + dest + '&key = ' + api_key)
#json method of response object
#return json format result
x = r.json()
#by default driving mode considered
#print value of x
print(x)
scrape_gmaps_data()发布于 2019-09-25 16:28:15
你必须移除“=”周围的空格。
比如:
r = requests.get(url + 'origins=' + source + '&destinations=' + dest + '&key=' + api_key)希望能帮上忙。
https://stackoverflow.com/questions/58102024
复制相似问题