嘿,现在我正在使用 Google ProtoRPC 和 Endpoints 开发后端 api。我正在使用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: ])
。奇怪的是,这只发生在方法 using @Model.query_method
,我有其他方法使用相同的系统,但 using@Model.method
并且它运行正常。
如果我在开发服务器中尝试过,有时它只是给我,RuntimeError: BadRequestError('missing key id/name',)
然后如果我只是重新保存 .py 文件并重试它,它会起作用(有时不会,另一个重新保存也可能使错误再次发生)。
谁能告诉我我的错误?谢谢