我是Python和Google AppEngine的新手,但有大约7年的编程经验 . 我也是StackOverflow的新手 .
我一直在尝试为我的个人项目设置一个简单的Google Cloud Endpoint API,并已完成并将完成的应用程序上传到Google App Engine .
以下是我的Endpoint API设置:
@endpoints.api(name='puzzle', version='v1', description='Puzzle Engine API')
和方法:
@endpoints.method(
PuzzleMessage, PuzzleMessage,
name='puzzle.generate',
http_method='GET',
path='generate'
)
@endpoints.method(
PuzzleMessage, PuzzleMessage,
name='puzzle.solve',
http_method='GET',
path='solve'
)
我的app.yaml看起来像:
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"
最后,services.py读取:
from google.appengine.ext import endpoints
from api import puzzle_api
application = endpoints.api_server([
puzzle_api.PuzzleAPI
], restricted=False)
现在,问题是,当我尝试访问https://my-app-name.appspot.com/_ah/api/discovery/v1/apis时,我看到的只是
未找到
此外,当我在https://developers.google.com/apis-explorer/?base=https:// my-app-name.appspot.com/_ah/api#p/上点击API Explorer时,服务列表为空,在JavaScript控制台中,我看到了错误超过https:// my-app-name.appspot.com/_ah/api/discovery/v1/apis .
在本地测试服务器上访问这些URL会产生完全不同的错误 . 当我尝试在localhost:8080 / _ah / api / discovery / v1 / apis的本地测试服务器上访问API Discovery时,我得到了
{“error”:{“message”:“BackendService.getApiConfigs Error”}}
而不是"Not Found" . 点击资源管理器https://developers.google.com/apis-explorer/?base=http://localhost:8080/_ah/api#p/现在在JavaScript控制台中也会显示500错误而不是404错误 .
我一直试图通过做很多谷歌搜索并尝试很多东西来解决这个问题,但我似乎无法继续下去 . 我非常感谢能从这个专业人士社区获得的任何帮助 .
谢谢 .
3 回答
改为 app.yaml
请参阅此处的文档:https://developers.google.com/appengine/docs/python/endpoints/api_server
您需要执行以下操作:
将您的app.yaml更改为:
Note :网址应该是
/_ah/spi/.*
而不是/_ah/api/.*
. 更改它,然后您可以在/_ah/api/explorer
访问您的API .尝试颠倒这些处理程序的顺序 . 通常的好习惯是始终将最常用的URL匹配器放在列表的末尾,以免它们捕获了旨在转到更具体的处理程序的内容 .