0

我正在尝试从我的端点 API 将数据放入服务器,但是当我调用 POST 请求时出现我不理解的错误。

我的消息类,没什么特别的:

# -*- coding: utf-8 -*-

from protorpc import messages

class UserCreateResponseMessage(messages.Message):
    """With this message we say if user put to the server was ok"""
    success = messages.BooleanField(1, default=False)

class UserCreateRequestMessage(messages.Message):
    """With this message we pass data to put into the server"""
    phone_number = messages.StringField(1, required=True)
    e_mail = messages.StringField(2, required=True)    
    password = messages.StringField(3, required=True)
    name = messages.StringField(4)
    birth_year = messages.IntegerField(5, required=True)
    birth_month = messages.IntegerField(6, required=True)
    birth_day = messages.IntegerField(7, required=True)

我的 api,一个只有一种方法的类,它将字段放入用户并尝试保存它:

# -*- coding: utf-8 -*-

from google.appengine.ext import endpoints
from protorpc import remote

from whis_api_messages import UserCreateResponseMessage
from whis_api_messages import UserCreateRequestMessage
from models import User

@endpoints.api(name='whis_api', version='v1',
               hostname='whisper-by-easierelephant.appspot.com',
               description='Whis API')
class WhisApi(remote.Service):
    """Class which defines Whisper API v1."""
    @endpoints.method(UserCreateRequestMessage, UserCreateResponseMessage,
                      http_method='POST',
                      path='users',
                      name='users.create')
    def users_create(self, request):
      """get the data and call to put the user in the database"""      
      user = User(parent = models.userbook_key())

      user.phone_number = request.phone_number           
      user.e_mail = request.e_mail     
      user.password = request.password
      user.name = request.name
      user.date_of_birth = datetime.date(year=request.birth_year,     month=request.birth_month, day=request.birth_day)
      user.profile_picture_name = 'empty'

      user.put()

      return UserCreateResponseMessage(success=True)

app = endpoints.api_server([WhisApi], 
                           restricted=False)

我的 app.yaml:

application: whisper-by-easierelephant
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /_ah/spi/.*
  script: whis_api.app
  secure: always

- url: /.*
  script: main.app
  secure: always 

libraries:
- name: webapp2
  version: latest
- name: pycrypto
  version: latest

当我尝试从 apis explorer 执行它时得到的响应:

503 Service Unavailable

- Show headers -

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "Internal Server Error"
   }
  ],
  "code": 503,
  "message": "Internal Server Error"
 }
}

我真的不知道发生了什么,我真的很绝望。我是端点的新手,所以每一个建议和建议都会受到赞赏。

4

1 回答 1

1

问题是我必须将我的文件“模型”和“日期时间”导入到 whis_api.py。

要查看从资源管理器执行应用程序时发生的情况,请转到https://appengine.google.com,单击您的应用程序,然后单击“日志”,您将看到执行期间发生的错误的详细版本服务器。

于 2013-09-06T05:59:47.383 回答