【问题标题】:Google app engine: object has no attribute ToMessage谷歌应用引擎:对象没有属性 ToMessage
【发布时间】:2016-12-01 09:24:52
【问题描述】:

我正在尝试实现一项服务,该服务检查登录用户是否在数据存储上,如果是则返回 True,如果不是则返回 False。 这是我正在使用的代码:

import endpoints

from google.appengine.ext import ndb
from protorpc import remote
from protorpc import messages

from endpoints_proto_datastore.ndb import EndpointsModel
from google.appengine.api import users

class AuthRes(messages.Message):
    message = messages.StringField(1)

class UserModel(EndpointsModel):
    user = ndb.UserProperty()

@endpoints.api(name='myapi', version='v1', description='My Little API')
class MyApi(remote.Service):

    @UserModel.method(path='myuser', http_method='GET', name='myuser.check')
    def UserCheck(self, cls):
        user = users.get_current_user()
        if user:
            myuser = cls.query().filter(cls.user.user_id() == user.user_id()).get()
            if not myuser:
                  return AuthRes(message="False")
            else:
                  return AuthRes(message="True")
        else:
            return AuthRes(message="False")


application = endpoints.api_server([MyApi], restricted=False)

我总是收到'AuthRes' object has no attribute 'ToMessage'

【问题讨论】:

  • 哪些行产生了错误?您可以发布堆栈跟踪吗?
  • return 语句是返回错误的语句
  • @TarikMokafih 你能发布完整的回溯吗?

标签: python-2.7 google-app-engine google-cloud-endpoints


【解决方案1】:

我相信而不是这个:

@UserModel.method(path='myuser', http_method='GET', name='myuser.check')

你想要这个:

from protorpc import message_types  # add at the top

@endpoints.method(message_types.VoidMessage, AuthRes, path='myuser', http_method='GET', name='myuser.check')

【讨论】:

    猜你喜欢
    • 2016-07-22
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多