当Google Cloud Endpoints服务器尝试与之通信时,该应用程序返回了错误

时间:2015-11-04 08:00:46

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

您好我是Google App Engine和Cloud Endpoints的新手。

我有一个提供Web应用程序的应用引擎。

我想将它与Cloud Endpoints一起使用。

所以我刚从这里添加了源代码:     https://cloud.google.com/appengine/docs/python/endpoints/getstarted/backend/write_api

但我无法部署应用并收到此错误消息:

Checking if Endpoints configuration has been updated.
07:13 AM Failed to update Endpoints configuration.  The app returned an error when the Google Cloud Endpoints server attempted to communicate with it.
07:13 AM See the deployment troubleshooting documentation for more information: https://developers.google.com/appengine/docs/python/endpoints/test_deploy#troubleshooting_a_deployment_failure

这是我的源代码

import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote

package = 'Hello'


class Greeting(messages.Message):
  """Greeting that stores a message."""
  message = messages.StringField(1)


class GreetingCollection(messages.Message):
  """Collection of Greetings."""
  items = messages.MessageField(Greeting, 1, repeated=True)


STORED_GREETINGS = GreetingCollection(items=[
    Greeting(message='hello world!'),
    Greeting(message='goodbye world!'),
])


@endpoints.api(name='helloworld', version='v1')
class HelloWorldApi(remote.Service):
  """Helloworld API v1."""

  @endpoints.method(message_types.VoidMessage, GreetingCollection,
                    path='hellogreeting', http_method='GET',
                    name='greetings.listGreeting')
  def greetings_list(self, unused_request):
    return STORED_GREETINGS

  ID_RESOURCE = endpoints.ResourceContainer(
      message_types.VoidMessage,
      id=messages.IntegerField(1, variant=messages.Variant.INT32))

  @endpoints.method(ID_RESOURCE, Greeting,
                    path='hellogreeting/{id}', http_method='GET',
                    name='greetings.getGreeting')
  def greeting_get(self, request):
    try:
      return STORED_GREETINGS.items[request.id]
    except (IndexError, TypeError):
      raise endpoints.NotFoundException('Greeting %s not found.' %
                                        (request.id,))

APPLICATION = endpoints.api_server([HelloWorldApi])

与教程完全相同

和我的app.yaml

application: my application id
version: application version
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /data
  script: MLP.app
  login: admin
- url: /insert_db
  script: MLP.app
  login: admin
- url: /validete
  script: MLP.app
  login: admin
- url: /stylesheets
  static_dir: stylesheets
- url: /js
  static_dir: js 
- url: /.*
  script: MLP.app
- url: /_ah/spi/.*
  script: MLP_mobile_backend.APPLICATION

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest
- name: pycrypto
  version: latest
- name: endpoints
  version: 1.0

MLP.py只是带有webapp2的网络服务

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

app.yamlscript: MLP_mobile_backend.APPLICATION开始,这意味着您的代码示例必须位于应用引擎项目根目录的MLP_mobile_backend.py文件中

.
├── app.yaml 
├── MLP.py 
└── MLP_mobile_backend.py

在该文件中定义了一个名为APPLICATION的端点api服务器,就像上面的代码示例一样。

APPLICATION = endpoints.api_server([HelloWorldApi])

满足这些要求后,此行指向如何访问您的终端:

@endpoints.api(name='helloworld', version='v1')

例如,假设您在端口8080上运行devserver的模块,并且想要访问 hellogreeting 路径:

@endpoints.method(message_types.VoidMessage, GreetingCollection,
                  path='hellogreeting', http_method='GET',
                  name='greetings.listGreeting')

您可以使用cURLhttpie您的浏览器http://localhost:8080/_ah/api/helloworld/v1/hellogreeting本地导航到devserver的默认模块,或者使用Google的API资源管理器{{3应该导致这个响应体:

{
 "items": [
  {
   "message": "hello world!"
  }, 
  {
   "message": "goodbye world!"
  }
 ]
}

在本地设置后,您可以部署它。

http://localhost:8080/_ah/api/explorer