Google应用程序引擎的Python API问题
我的API遇到问题,无法创建用户记录/将其存储在Google数据存储中。我收到下面列出的JSON响应 另一件我觉得奇怪的事情是,当使用位于右上角的GoogleAPIsExplorer时,它有一个红色感叹号,表示方法需要授权。它希望我为用户电子邮件授权OAUTH作用域 更新:这是我通过GAE获得的错误日志Google应用程序引擎的Python API问题,python,google-app-engine,google-cloud-endpoints,Python,Google App Engine,Google Cloud Endpoints,我的API遇到问题,无法创建用户记录/将其存储在Google数据存储中。我收到下面列出的JSON响应 另一件我觉得奇怪的事情是,当使用位于右上角的GoogleAPIsExplorer时,它有一个红色感叹号,表示方法需要授权。它希望我为用户电子邮件授权OAUTH作用域 更新:这是我通过GAE获得的错误日志 Encountered unexpected error from ProtoRPC method implementation: ServerError (Method Photosw
Encountered unexpected error from ProtoRPC method implementation: ServerError (Method PhotoswapAPI.user_create expected response type <class 'photoswap_api_messages.UserCreateResponseMessage'>, sent <type 'NoneType'>)
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 419, in invoke_remote_method
type(response)))
ServerError: Method PhotoswapAPI.user_create expected response type <class 'photoswap_api_messages.UserCreateResponseMessage'>, sent <type 'NoneType'>
photoswap_api.py
photoswap_api_messages.py
models.py
main.py
app.yaml
在这里:
您声明该方法返回UserCreateResponseMessage;但在这里:
def user_create(self, request):
entity = User(username=request.username, email=request.email,
password=request.password)
entity.put()
您没有返回任何内容,即返回无…此处:
您声明该方法返回UserCreateResponseMessage;但在这里:
def user_create(self, request):
entity = User(username=request.username, email=request.email,
password=request.password)
entity.put()
您没有返回任何内容,即返回一个无…我刚刚意识到这一点。我对后端工作和python比较陌生。谢谢你的帮助,真的很快。存储实体后,如何返回该实体。我希望响应是被存储用户的JSON。return UserCreateResponseMessageemail=request.email,password=request.password上面定义的UserCreateResponseMessage有三个字段——email、username和id,因此您必须设置它们;它没有密码字段-这只是在请求中。很抱歉,我实际上是在处理一组不同的消息。这仍然帮助解决了我的问题。谢谢,我才意识到这一点。我对后端工作和python比较陌生。谢谢你的帮助,真的很快。存储实体后,如何返回该实体。我希望响应是被存储用户的JSON。return UserCreateResponseMessageemail=request.email,password=request.password上面定义的UserCreateResponseMessage有三个字段——email、username和id,因此您必须设置它们;它没有密码字段-这只是在请求中。很抱歉,我实际上是在处理一组不同的消息。这仍然帮助解决了我的问题。非常感谢。
from protorpc import messages
class UserCreateRequestMessage:
email = messages.StringField(1)
password = messages.StringField(2)
class UserCreateResponseMessage:
email = messages.StringField(1)
username = messages.StringField(2)
id = messages.IntegerField(3)
from google.appengine.ext import ndb
TIME_FORMAT_STRING = '%b %d, %Y %I:%M:%S %p'
class User(ndb.Model):
username = ndb.StringProperty(required=True)
email = ndb.StringProperty(required=True)
id = ndb.IntegerProperty()
class Post(ndb.Model):
user_id = ndb.IntegerProperty(required=True)
id = ndb.IntegerProperty(required=True)
desc = ndb.StringProperty(required=False)
import webapp2
from protorpc import remote
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world!')
app = webapp2.WSGIApplication([
('/_ah/spi/.*', MainHandler)
], debug=True)
application: caramel-theory-800
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
# Endpoints handler
- url: /_ah/spi/.*
script: photoswap_api.APPLICATION
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
@endpoints.method(UserCreateRequestMessage, UserCreateResponseMessage,
def user_create(self, request):
entity = User(username=request.username, email=request.email,
password=request.password)
entity.put()