我面對上部署AppEngine上的應用程序的一個問題:它不使用谷歌的API探險回到了我的位置。AppEngine上的端點,原數據存儲問題與user_required:沒有返回記錄
我做了定義./datastore_models/location.py文件:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from google.appengine.ext import ndb
from google.appengine.api import search
from endpoints_proto_datastore.ndb import EndpointsModel
class Location(EndpointsModel):
name = ndb.StringProperty(required=True, verbose_name="Name")
description = ndb.TextProperty(required=True, verbose_name="Description")
address = ndb.StringProperty(required=True, verbose_name="Address")
coordinate = ndb.GeoPtProperty(required=False, verbose_name="Coordinate")
enable_geocode = ndb.BooleanProperty(default=False, verbose_name="Enable geocode")
active = ndb.BooleanProperty(default=True, verbose_name="Active")
owner = ndb.UserProperty(required=False, verbose_name="Owner")
而且我已經有一個簡單的./main.py文件:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import endpoints
from protorpc import remote
from datastore_models.location import Location
WEB_CLIENT_ID = 'ID.apps.googleusercontent.com'
@endpoints.api(name='uemd', version='v1',
description='API for locations, objects and events',
audiences=[WEB_CLIENT_ID, endpoints.API_EXPLORER_CLIENT_ID])
class UemDAPI(remote.Service):
@Location.method(user_required=True, request_fields=('name', 'description', 'address', 'enable_geocode'),
path='location', http_method='POST', name='location.insert')
def LocationInsert(self, location):
location.owner = endpoints.get_current_user()
location.put()
return location
@Location.method(user_required=True, request_fields=('id',),
path='location/{id}', http_method='GET', name='location.get')
def LocationGet(self, location):
if not location.from_datastore:
raise endpoints.NotFoundException('Location not found.')
return location
@Location.query_method(user_required=True, query_fields=('active', 'limit', 'order', 'pageToken'),
path='locations', name='location.list')
def LocationList(self, query):
return query.filter(Location.owner == endpoints.get_current_user())
app = endpoints.api_server([UemDAPI], restricted=False)
當我現在要做的通話「GET https://uemd-core.appspot.com/_ah/api/uemd/v1/locations」在使用POST方法之前,我沒有收到我創建的位置。我剛剛收到:
{
"kind": "uemd#locationItem",
"etag": "\"llW4_dZC50NEF69z_hZurfpZb1s/wnbopBN8xedxeOulX5Nry_3uwCw\""
}
執行「GET https://uemd-core.appspot.com/_ah/api/uemd/v1/location/5634387206995968」確實返回一個位置如預期。
在AppEngine上的日誌我看到下面的調試消息:
id_token verification failed: Can't parse header:ɭ�
但是我也看到這個消息對於它不會返回一個位置的方法...
運行在相同的查詢dev_appserver.py提出:
RuntimeError: UnicodeDecodeError('utf8', "id_token verification failed: Can't parse header: \xc9\xad\xbd", 52, 53, 'invalid start byte')
到目前爲止,我的確遵循了終點,原數據存儲的例子,但我也想我的數據存儲模型存儲在一個額外的目錄(datast ore_models)。 location.insert和location.get方法正在工作,但沒有location.list。所有這些方法都顯示「無法解析頭」的消息......我該如何解決這個問題?
乾杯
我仍然有同樣的問題。檢索一個位置確實有效,多個位置沒有。
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 1302, in communicate
req.respond()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 831, in respond
self.server.gateway(self).respond()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 2115, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 269, in __call__
return app(environ, start_response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 311, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 148, in __call__
self._flush_logs(response.get('logs', []))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/request_handler.py", line 284, in _flush_logs
apiproxy_stub_map.MakeSyncCall('logservice', 'Flush', request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 94, in MakeSyncCall
return stubmap.MakeSyncCall(service, call, request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 328, in MakeSyncCall
rpc.CheckSuccess()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl
self.request, self.response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 200, in MakeSyncCall
self._MakeRealSyncCall(service, call, request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 234, in _MakeRealSyncCall
raise pickle.loads(response_pb.exception())
RuntimeError: UnicodeDecodeError('utf8', "id_token verification failed: Can't parse header: \xc9\xad\xbd", 52, 53, 'invalid start byte')