unable to load configuration from uwsgi

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

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() 

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 

The output is as follows

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 

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?

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

Any suggestions would be helpful

Thanks

回答1:

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

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.

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__':.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!