我在为Google App Engine上的Python查询获取正确响应方面遇到问题。Google App Engine数据存储上的Python API查询
这是来自GAE的LOG,它成功地打印出与查询参数匹配的对象,但现在我试图将该对象数据作为JSON发回。我正在创建一个基本的用户认证系统,该系统使用电子邮件和密码查询USER对象,如果存在,则返回所有数据。
如何分解此查询以返回找到的数据?
E 00:21:06.352 Encountered unexpected error from ProtoRPC method implementation: AttributeError ('list' object has no attribute 'email')
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/wsgi/service.py", line 181, in protorpc_service_app
response = method(instance, request)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/endpoints-1.0/endpoints/api_config.py", line 1332, in invoke_remote
return remote_method(service_instance, request)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/remote.py", line 412, in invoke_remote_method
response = method(service_instance, request)
File "/base/data/home/apps/s~caramel-theory-800/1.381271940209425490/photoswap_api.py", line 34, in user_auth
return UserCreateResponseMessage(email=query.email, password=query.password, username=query.username,
AttributeError: 'list' object has no attribute 'email'
E 00:21:06.360 [User(key=Key('User', 5086441721823232), email=u'pop', password=u'top', username=u'yop')]
这里是端点API
我相信这个问题是代码的最后一行的地方改掉返回查询(UserAuthResponseMessage)的结果中..
@endpoints.method(UserAuthRequestMessage, UserAuthResponseMessage,
path='user', http_method='GET',
name='user.auth')
def user_auth(self, request):
# create some type of query to check for email address, and than check to see if passwords match
query = User.query(User.email == request.email, User.password == request.password).fetch()
print query
# return the info from the server
return UserCreateResponseMessage(email=query[0].email, password=query[0].password, username=query[0].username,
id=query[0].key.id())
APPLICATION = endpoints.api_server([PhotoswapAPI], restricted=False)
此“答案”中的代码仍然不正确,请根据其前面的文本进行编辑和纠正。 –
我不太清楚我失踪的是什么。我利用.get()返回1结果,并且我能够引用来自查询的电子邮件,密码,用户名和ID值。返回的JSON是我在响应消息中查找的内容。你能否详细说明那是什么“错误”? –