AppEngine Google Cloud Endpoint - discovery not found

人盡茶涼 提交于 2020-01-01 05:48:06

问题


I am quite new to Python and Google AppEngine, but have had around 7 years of programming experience. I am also new to StackOverflow.

I've been trying to set up a simple Google Cloud Endpoint API for my personal project, and have finished and uploaded the finished app to Google App Engine.

Here are my Endpoint API settings:

@endpoints.api(name='puzzle', version='v1', description='Puzzle Engine API')

And methods:

@endpoints.method(
        PuzzleMessage, PuzzleMessage,
        name='puzzle.generate',
        http_method='GET',
        path='generate'
    )

@endpoints.method(
        PuzzleMessage, PuzzleMessage,
        name='puzzle.solve',
        http_method='GET',
        path='solve'
    )

My app.yaml looks like:

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.app

# Endpoints handler
- url: /_ah/api/.*
  script: services.application

libraries:
- name: webapp2
  version: "2.5.2"

And finally services.py reads:

from google.appengine.ext import endpoints
from api import puzzle_api

application = endpoints.api_server([
                               puzzle_api.PuzzleAPI
                           ], restricted=False)

Now, the problem is that when I try to reach https://my-app-name.appspot.com/_ah/api/discovery/v1/apis, all I see is

Not Found

Also, when I hit the API Explorer at https://developers.google.com/apis-explorer/?base=https://my-app-name.appspot.com/_ah/api#p/, the list of Services is empty, and in the JavaScript console, I see a 404 error over https://my-app-name.appspot.com/_ah/api/discovery/v1/apis.

Hitting these URLs on local test server gives quite different errors. When I try to reach the API Discovery on local test server at localhost:8080/_ah/api/discovery/v1/apis, I get

{"error": {"message": "BackendService.getApiConfigs Error"}}

instead of "Not Found". Hitting the Explorer at https://developers.google.com/apis-explorer/?base=http://localhost:8080/_ah/api#p/ would now show 500 error instead of 404 in the JavaScript console as well.

I've been trying to solve this by doing many Google Searches and trying many things out, but I just cannot seem to be able to proceed any further. I would very much appreciate any help I can get from this community of professionals.

Thanks.


回答1:


See the documentation here: https://developers.google.com/appengine/docs/python/endpoints/api_server

You need to do the following:

Change your app.yaml to:

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /_ah/spi/.*
  script: services.application

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"

Note: The url should be /_ah/spi/.* not /_ah/api/.*. Change it, then you can access your api at /_ah/api/explorer.




回答2:


- url: .*
  script: main.app

# Endpoints handler
- url: /_ah/api/.*
  script: services.application

Try reversing the order of these handlers. It's typically good practice to always put the most general URL-matchers at the end of the list, lest they catch something that was meant to go to a more specific handler.




回答3:


Change into app.yaml

# Endpoints handler
- url: /_ah/spi/.*
  script: services.application

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


来源:https://stackoverflow.com/questions/15675587/appengine-google-cloud-endpoint-discovery-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!