【问题标题】:The app returned an error when the Google Cloud Endpoints server attempted to communicate with it当 Google Cloud Endpoints 服务器尝试与其通信时,该应用返回错误
【发布时间】:2016-02-04 15:13:33
【问题描述】:

您好,我是 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 的网络服务

我该如何解决这个问题?

【问题讨论】:

  • 部署前,能不能在本地测试一下?
  • 我可以在本地启动程序...但是我找不到教程所说的任何带有 helloapi 的 API 名称

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


【解决方案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 上运行您的开发服务器模块,并且您想要访问 hellogreeting 路径:

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

您可以使用cURLhttpie您的浏览器 在本地导航到开发服务器的默认模块http://localhost:8080/_ah/api/helloworld/v1/hellogreeting 或使用Google 的API 浏览器http://localhost:8080/_ah/api/explorer 这应该会导致此响应正文:

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

在本地设置好之后,就可以部署它了。

More here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2019-01-28
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    相关资源
    最近更新 更多