【问题标题】:Python Flask: Go from Swagger YAML to Google App Engine?Python Flask:从 Swagger YAML 到 Google App Engine?
【发布时间】:2017-02-24 22:39:01
【问题描述】:

我已经使用 Swagger 编辑器创建了一个 REST API,并且我请求了 Python Flask 的服务器代码下载。我正在尝试将其部署到 Google Cloud Platform(我认为这是最新名称?还是仍然是 GAE?)但我需要填补一些空白。

我知道 Swagger 代码有效,因为我已在本地部署它,没有任何问题。但是,它直接使用 connexion 库而不是 Flask。

对于如何将 GCP 的 app.yaml 文件和正确的入口点合并到生成的代码中,我很迷茫。此外,我知道生成的代码声明了它自己的应用服务器,我认为你不需要为 GCP 做。 这是我当前的 app.yaml

application: some-app-name
version: 1
runtime: python27
api_version: 1
threadsafe: yes
entrypoint: python app.py

libraries:
- name: connexion
  version: "latest"

这是我的 app.py

import connexion

if __name__ == '__main__':
    app = connexion.App(__name__, specification_dir='./swagger/')
    app.add_api('swagger.yaml', arguments={'title': 'this is my API'})
    app.run(port=8080)

我现在遇到的主要错误是

google.appengine.api.yaml_errors.EventError: the library "connexion" is not supported

我有一种感觉,这是因为我在 app.py 中声明应用服务器的方式 - 可能不需要它。我将如何修改此文件以仍然使用我的 Swagger 代码但在 GCP 上运行?

【问题讨论】:

  • 坚持 GAE,GCP 包括 GAE,但也包括其他 Google 产品,其中一些与 GAE 完全无关:cloud.google.com/products

标签: python google-app-engine flask swagger google-cloud-platform


【解决方案1】:

您的文件中似乎有一些不一致之处,不清楚您打算将其设为standard environment app.yaml file 还是flexible environment。我不知道,因为我不熟悉招摇和烧瓶。

如果它应该是标准环境,那么:

通过Getting Started with Flask on App Engine Standard Environment 可能是个好主意

但是,如果您的目标是一个灵活的环境 app.yaml 文件,那么:

  • 您需要其中的env: flexruntime: python 配置(原始答案中的vm: trueruntime: python27 现在已弃用)
  • installing/specifying dependencies 以不同的方式完成,而不是通过 libraries 部分。

【讨论】:

  • 这里有些东西发生了变化。正如我通过准确搜索这个问题找到的那样,这里有一些东西: - vm: true 已被 env: flex 取代,它还要求将运行时行从 runtime: python27 更改为 runtime: python
猜你喜欢
  • 2018-04-15
  • 2015-02-10
  • 2015-12-08
  • 2016-08-18
  • 1970-01-01
  • 2011-03-09
  • 2013-11-12
  • 2021-01-02
  • 2021-11-05
相关资源
最近更新 更多