【问题标题】:how to use gunicorn with swagger_server on flask如何在烧瓶上使用 gunicorn 和 swagger_server
【发布时间】:2018-06-26 00:39:04
【问题描述】:

我正在尝试使用以下代码在 ec2 实例上使用 gunicorn 启动 swagger 服务器:

我试过了:

gunicorn -w 4 -b 0.0.0.0:8080 -p pidfile -D swagger_server:app

还有这个:

gunicorn -w 4 -b 0.0.0.0:8080 -p pidfile -D "python3 -m swagger_server":app

甚至这个:

gunicorn -w 4 -b 0.0.0.0:8080 -p pidfile -D __main__:app

我怎样才能让它工作?

有效的原始python代码:python3 -m swagger_server

【问题讨论】:

    标签: python flask swagger gunicorn


    【解决方案1】:

    这个对我有用:

    gunicorn "swagger_server.__main__:app" -w 4 -b 0.0.0.0:8080
    

    【讨论】:

      【解决方案2】:

      你正在尝试做的相当于:

      from swagger_server.__main__ import main
      

      要使其与 gunicorn 一起使用,请尝试:

      gunicorn "swagger_server.__main__:main" -w 4 -b 0.0.0.0:8080`
      

      如果您遇到错误:

      ImportError: 没有名为 swagger_server 的模块

      PYTHONPATH 添加到 gunicorn 命令:

      gunicorn "swagger_server.__main__:main" -w 4 -b 0.0.0.0:8080 --pythonpath path_to_swagger_server
      

      【讨论】:

      【解决方案3】:

      您的应用程序不是在寻找具有类似 [app:main] 部分的配置文件吗?

      【讨论】:

      • 我不确定你的意思。我正在使用flask-swagger,它在文件夹中有 main.py 文件。
      【解决方案4】:
      gunicorn -b 0.0.0.0:8080 main:app --reload
      

      这应该是正确的语法,显然请确保您在正确的目录中并获取您的 virtualenv。

      【讨论】:

      • 尝试启动服务器时出现错误:ImportError: No module named main
      • 当前文件夹中有一个文件_main_.py
      猜你喜欢
      • 2016-03-19
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2016-08-30
      • 2022-01-21
      • 2012-11-19
      相关资源
      最近更新 更多