嘿,所以现在我正在使用谷歌ProtoRPC和端点开发后端应用程序接口。我使用的是endpoints-proto-datastore库。
这里发生了一些奇怪的事情,下面是EndpointsModel类
class AssetData(EndpointsModel):
type = msgprop.EnumProperty(AssetType, indexed=True)
def auth_id_set(self, value):
if ApplicationID.get_by_id(value) is None:
raise endpoints.UnauthorizedException('no auth_id')
self._auth_id = value
@EndpointsAliasProperty(required=True, setter=auth_id_set, property_type=messages.IntegerField)
def auth_id(self):
return self._auth_id
def app_id_set(self, value):
if ApplicationID.query(ApplicationID.app_id == value).get() is None:
raise endpoints.UnauthorizedException('wrong app_id')
self._app_id = value
if self.check_auth_app_id_pair(self.auth_id, value):
self._app_id = value
else:
raise endpoints.BadRequestException('auth_id and app_id mismatch')
@EndpointsAliasProperty(required=True, setter=app_id_set)
def app_id(self):
return self._app_id
@staticmethod
def check_auth_app_id_pair(authen_id, applic_id):
dat = ApplicationID.get_by_id(authen_id)
if dat.app_id != applic_id:
return False
else:
return True这是API类
@endpoints.api(...)
class AssetDatabaseAPI(remote.Service):
@AssetData.query_method(query_fields=('limit', 'order', 'pageToken', 'type', 'auth_id', 'app_id'),
path='assets', http_method='GET', name='assets.getAssetMultiple')
def assets_get_multiple(self, query):
return query当我部署它时,每次我试图访问assets.getMultipleAssets时,它只会给我这个错误raised BadRequestError(Key path element must not be incomplete: [ApplicationID: ])。奇怪的是,这只发生在使用@Model.query_method的方法上,我有其他使用相同系统的方法,但是使用@Model.method,它运行得很好。
如果我在开发服务器中尝试它,有时它只是给我RuntimeError: BadRequestError('missing key id/name',),然后如果我只是重新保存.py文件并重试,它将会工作(有时不会,再次重新保存也会使错误再次发生)。
有人能告诉我我的错误吗?谢谢
发布于 2016-01-25 14:54:16
我认为你的问题在于如何调用这个方法--它是一个静态方法,所以你必须通过类来访问它,而不是实例(self):
if AssetData.check_auth_app_id_pair(self.auth_id, value):
self._app_id = value
else:
raise endpoints.BadRequestException('auth_id and app_id mismatch')https://stackoverflow.com/questions/34982879
复制相似问题