从我的端点API执行post请求时出错503

时间:2013-09-05 23:48:05

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

我正在尝试从我的端点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"
 }
}

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

1 个答案:

答案 0 :(得分:1)

问题是我必须将文件'models'和'datetime'导入whis_api.py。

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