首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@EndpointsAliasProperty和@Model.query_method导致BadRequestError(Key path元素不能不完整:...)

@EndpointsAliasProperty和@Model.query_method导致BadRequestError(Key path元素不能不完整:...)
EN

Stack Overflow用户
提问于 2016-01-25 07:26:36
回答 1查看 228关注 0票数 0

嘿,所以现在我正在使用谷歌ProtoRPC和端点开发后端应用程序接口。我使用的是endpoints-proto-datastore库。

这里发生了一些奇怪的事情,下面是EndpointsModel

代码语言:javascript
复制
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类

代码语言:javascript
复制
@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文件并重试,它将会工作(有时不会,再次重新保存也会使错误再次发生)。

有人能告诉我我的错误吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-01-25 14:54:16

我认为你的问题在于如何调用这个方法--它是一个静态方法,所以你必须通过类来访问它,而不是实例(self):

代码语言:javascript
复制
    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')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34982879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档