【发布时间】:2020-02-20 14:40:43
【问题描述】:
我已阅读以下与 uwsgi 相关的问题,有趣的是,到目前为止没有任何帮助:
- Flask and uWSGI - unable to load app 0 (mountpoint='') (callable not found or import error)
- uwsgi-nginx-flask: unable to load app 0 (mountpoint='') (callable not found or import error)
- unable to load app 0 (mountpoint='') - Flask app with uwsgi
看来我需要将应用程序导入为application,因为uWSGI 试图找到应用程序变量。
from tf_api import create_app as application
if __name__ == "__main__":
application = application()
application.run()
else:
print("---------------------->", __name__)
application = application()
当我运行以下命令时:
uwsgi --socket 0.0.0.0:80 --protocol=tcp -w wsgi:app
它转到else 部分并输出:
----------------------> wsgi
2020-02-20 14:25:22,168 [tf_core] Initialized! [testing=False]
2020-02-20 14:25:22,176 [tf_api] {"msg": "Initialized! Testing: False", "logger_name": "tf_api", "log_level": "DEBUG", "timestamp": "2020-02-20T14:25:22.176664"}
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 27143, cores: 1)
从应用程序打印一些日志,然后打印no app loaded!
当我将 application.run(host='0.0.0.0') 放入 else 时,似乎应用程序开始运行,但在烧瓶默认端口 5000 上而不是在 uWSGI 上:
----------------------> wsgi
2020-02-20 14:36:57,333 [tf_core] Initialized! [testing=False]
2020-02-20 14:36:57,339 [tf_api] {"msg": "Initialized! Testing: False", "logger_name": "tf_api", "log_level": "DEBUG", "timestamp": "2020-02-20T14:36:57.339723"}
* Serving Flask app "tf_api" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
2020-02-20 14:36:57,405 [werkzeug] * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
2020-02-20 14:36:57,406 [werkzeug] * Restarting with stat
unable to load configuration from /usr/local/lib/python3.6/dist-packages/tf_api/uwsgi
但是给出了与unable to load configuration from 相关的错误。 created_app 返回app。大家觉得uswgi里面找不到app的原因是什么?
【问题讨论】: