无法从 uwsgi 加载配置 [英] unable to load configuration from uwsgi

查看:29
本文介绍了无法从 uwsgi 加载配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Python 应用程序中有以下设置

I have below setup in my Python application

server.py

from bots.flask_app import app
from bots.flask_app.api import api
from bots.flask_app.public import public
from bots import db

from bots.commons.helpers.flask.json.serializer import make_alternative_encoder

from flask_debugtoolbar import DebugToolbarExtension

import logging

import bots.commons.managers.configuration as ConfigurationManager

logger = logging.getLogger()


#######
# Public functions
#######
def setup_db_and_app():
    # Flask application bootstrap
    config = ConfigurationManager.get_flask_rest_config()
    app.config.update(config)
    logger.debug('Flask configuration object: %s', app.config)

    # MongoDB connection initialization
    db.init_app(app)

    # Debug toolbar enabled only if Flask in debug mode
    if ConfigurationManager.get_raw_flask_rest_config()['flask']['debug']:
        DebugToolbarExtension(app)

    # Replace the serializer with the custom one (for ObjectId and DateTime serialization)
    app.json_encoder = make_alternative_encoder(app.json_encoder)

    # Register the components
    app.register_blueprint(api)
    app.register_blueprint(public)


def start_server():
    setup_db_and_app()
    logger.debug('Registered routes: %s', app.url_map)
    app.run(host='0.0.0.0')

main.py

import bots.flask_app.server as FlaskApp

import bots.commons.managers.log as LogManager

# Logging initialization
LogManager.init_logging()

# Defined in server.py
FlaskApp.start_server()

我想看看这个涂抹器是否可以由 uwsgi 提供如下

I am trying to see whether this applicator can bed served by uwsgi as below

uwsgi --socket 0.0.0.0:8080 --protocol=http -w main

输出如下

INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
INFO:werkzeug: * Restarting with stat
unable to load configuration from uwsgi

我的问题1. 在哪里可以找到导致此问题的配置?2. main.py 是否可以定义为可调用对象并作为-w 的参数使用?

My questions 1. Where can I find the configurations which are causing this issue? 2. Can main.py be defined as a callable and used as a parameter for -w?

这是一个已经由某人编写的应用程序,我正在尝试通过 uwsgi 提供此应用程序.

This is an app which is already written by someone and I am trying make this application served through uwsgi.

任何建议都会有帮助

谢谢

推荐答案

我也遇到了无法从 uwsgi 加载配置"错误.根据flask uwsgi docs:

I had the 'unable to load configuration from uwsgi' error too. According to flask uwsgi docs:

请提前确保您的应用程序文件中的任何 app.run() 调用都在 if __name__ == '__main__': 块内或移动到单独的文件中.只要确保它没有被调用,因为如果我们将该应用程序部署到 uWSGI,这将始终启动一个我们不想要的本地 WSGI 服务器.

Please make sure in advance that any app.run() calls you might have in your application file are inside an if __name__ == '__main__': block or moved to a separate file. Just make sure it’s not called because this will always start a local WSGI server which we do not want if we deploy that application to uWSGI.

我将 app.run() 移动到 if __name__ == '__main__':,问题就解决了.也许你可以尝试将 FlaskApp.start_server() 放在 if __name__ == '__main__': 下.

I move app.run() to if __name__ == '__main__':, and the problem solved. Maybe you can try to put FlaskApp.start_server() under if __name__ == '__main__':.

这篇关于无法从 uwsgi 加载配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆