簡體   English   中英

當Google Cloud Endpoints服務器嘗試與之通信時,該應用返回了錯誤

[英]The app returned an error when the Google Cloud Endpoints server attempted to communicate with it

嗨,我是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的Web服務

我該如何解決這個問題?

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的模塊,並且想要訪問問候路徑:

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

您可以使用cURLhttpie瀏覽器http:// localhost:8080 / _ah / api / helloworld / v1 / hellogreeting上本地瀏覽到devserver的默認模塊,也可以在http:// localhost:8080 / _ah上使用Google的API資源管理器/ api / explorer ,它將導致以下響應主體:

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

一旦在本地設置好它,就可以部署它。

這里更多

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM