我在爲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是我在響應消息中查找的內容。你能否詳細說明那是什麼「錯誤」? –