Python 3.x 错误:flask_appbuilder.security.sqla.manager:尝试使用gunicorn启动应用程序时,数据库创建和初始化失败

Python 3.x 错误:flask_appbuilder.security.sqla.manager:尝试使用gunicorn启动应用程序时,数据库创建和初始化失败,python-3.x,linux,gunicorn,flask-appbuilder,Python 3.x,Linux,Gunicorn,Flask Appbuilder,我已经使用flask_appbuilder构建了一个应用程序。我试图使用gunicorn为应用程序提供服务,但出现以下错误: $ gunicorn app:app [2021-05-25 09:18:40 +0300] [1211266] [INFO] Starting gunicorn 20.1.0 [2021-05-25 09:18:40 +0300] [1211266] [INFO] Listening at: http://127.0.0.1:8000 (1211266) [2021-0

我已经使用flask_appbuilder构建了一个应用程序。我试图使用gunicorn为应用程序提供服务,但出现以下错误:

$ gunicorn app:app
[2021-05-25 09:18:40 +0300] [1211266] [INFO] Starting gunicorn 20.1.0
[2021-05-25 09:18:40 +0300] [1211266] [INFO] Listening at: http://127.0.0.1:8000 (1211266)
[2021-05-25 09:18:40 +0300] [1211266] [INFO] Using worker: sync
[2021-05-25 09:18:40 +0300] [1211276] [INFO] Booting worker with pid: 1211276
2021-05-25 09:18:49,374:ERROR:flask_appbuilder.security.sqla.manager:DB Creation and initialization failed: Can't load plugin: sqlalchemy.dialects:None
应用程序文件如下所示

init.py 导入日志记录

from flask import Flask, request
from flask_graphql import GraphQLView
from flask_appbuilder import AppBuilder, SQLA
from .gql_schema import schema

"""
Logging configuration
"""

logging.basicConfig(format="%(asctime)s:%(levelname)s:%(name)s:%(message)s")
logging.getLogger().setLevel(logging.DEBUG)

app = Flask(__name__)
app.config.from_object("config")
db = SQLA(app)
appbuilder = AppBuilder(app, db.session)


from . import models, views, gql_schema, api

app.add_url_rule(
    "/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True)
)
还有cconfig.py

import os
from flask_appbuilder.security.manager import (
    AUTH_OID,
    AUTH_REMOTE_USER,
    AUTH_DB,
    AUTH_LDAP,
    AUTH_OAUTH,
)

basedir = os.path.abspath(os.path.dirname(__file__))

# Your App secret key
SECRET_KEY = "my secret key"
DB_ENGINE = os.environ.get('DB_ENGINE')
DB_USER = os.environ.get('DB_USER')
DB_PASSWORD = os.environ.get('DB_PASSWORD')
DB_NAME = os.environ.get('DB_NAME')
DB_HOST = os.environ.get('DB_HOST')
SQLALCHEMY_DATABASE_URI = f'{DB_ENGINE}://{DB_USER}:{DB_PASSWORD}@{DB_HOST}/{DB_NAME}'
SQLALCHEMY_TRACK_MODIFICATIONS = False
FAB_API_SWAGGER_UI = True
FAB_API_SHOW_STACKTRACE = True

有什么问题吗?

我知道问题出在哪里了。启动应用程序时,db连接的.env变量为,或返回None,因此会出现错误

我必须安装以支持

安装后,现在可以访问变量。

我正在使用flask twisted运行我的应用程序。以下是我补充的内容

用于运行应用程序的server.py文件

from twisted.application.service import Application
from app import twisted


PORT = 8010

application = Application('twisted-flask')
twisted.run(run_reactor=False, port=PORT)
启动应用程序的bash(start.sh)文件

#!/bin/bash
echo "----- Starting Application -----"
source venv/bin/activate

path=${PWD}
cd $path

command pip install -r $path/requirements.txt

#
export PYTHONPATH=$PATH:$path
export CDLP_SETTINGS_MODULE=config.Config


twistd -y server.py