INVALID_REQUEST:Google App Engine上的距离矩阵API

时间:2019-03-27 12:09:20

标签: python google-app-engine google-distancematrix-api

我在python3.7上使用Distance Matrix API,在我的本地计算机上工作正常,但是当我在Google App Engine上部署它时,出现以下错误:

Traceback (most recent call last):    
File "/env/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app      response = self.full_dispatch_request()    
File "/env/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request      rv = self.handle_user_exception(e)    
File "/env/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception      reraise(exc_type, exc_value, tb)    
File "/env/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise      raise value    
File "/env/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request      rv = self.dispatch_request()    
File "/env/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request      return self.view_functions[rule.endpoint](**req.view_args)    
File "/srv/main.py", line 116, in vr      distances = build_distance(cities)    
File "/srv/main.py", line 61, in build_distance      result = gmaps.distance_matrix(nodes, nodes, mode='driving')   
File "/env/lib/python3.7/site-packages/googlemaps/client.py", line 365, in wrapper      result = func(*args, **kwargs)    
File "/env/lib/python3.7/site-packages/googlemaps/distance_matrix.py", line 138, in distance_matrix      return client._request("/maps/api/distancematrix/json", params)    
File "/env/lib/python3.7/site-packages/googlemaps/client.py", line 260, in _request      result = self._get_body(response)    
File "/env/lib/python3.7/site-packages/googlemaps/client.py", line 290, in _get_body      body.get("error_message"))  googlemaps.exceptions.ApiError: INVALID_REQUEST

我的代码:

def retrieve_cities(string):
    lats=[]
    lons=[]
    for item in string.split("|"):
        lats.append(float(item.split(",")[0]))
        lons.append(float(item.split(",")[1]))
    return zip(lats,lons)

def build_distance(nodes):
    if True:
        Sgmaps = googlemaps.Client(key='[KEY]')
        result = gmaps.distance_matrix(nodes, nodes, mode='driving') #<<< ERROR HERE

def vr():
    n = "31.94,35.93|29.16,36.07|31.94,35.92|31.94,35.92|30.82,35.97"
    cities = retrieve_cities(n)
    distances = build_distance(cities)
    #(path, distance) = find_route(distances,cities)
    #data = {"distance":distance,"path":path,"message":""}
    return jsonify(distances)

能否请您说明为什么它可以在本地主机上而不在Google App引擎环境上运行?

0 个答案:

没有答案