烧瓶和烧瓶安全性

时间:2020-06-28 13:37:21

标签: apache flask mod-wsgi wsgi flask-security

我使用带有Flask和Flask-Security的小型应用程序(依赖于Flask-SQLAlchemy for DB)。 我在虚拟环境中使用Python 3.8。

我有一个奇怪的错误:

result from PyCharm console

我不明白为什么?抱歉。 有人可以帮我吗?

第二步,我想将该解决方案部署在测试服务器上(Debian Buster具有apache,通常需要所有东西)。

我写了wcgi文件:

#!/usr/bin/python3
import sys
sys.stdout = sys.stderr
activate_this = '/usr/local/venv/bin/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))

和Apache的conf文件:

<VirtualHost *:5000>
    ServerName www.…
    ServerAlias …

    DocumentRoot /var/www/flask

    ErrorLog ${APACHE_LOG_DIR}/flask.error.log
    CustomLog ${APACHE_LOG_DIR}/flask.access.log combined


    WSGIDaemonProcess flaskapp threads=5
    WSGIScriptAlias /flasktest /var/www/flask/app.wsgi process-group=flaskapp application-group=%{GLOBAL}

    Alias /favicon.ico /var/www/flask/static/favicon.ico
    Alias /static/ /var/www/flask/static/

    <Directory /var/www/static>
        WSGIScriptReloading On
        Require all granted
    </Directory>

    <Directory /var/www/flask>
        WSGIProcessGroup flaskapp
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        Require all granted
    </Directory>

</VirtualHost>

对于部署应用程序是否正确,模块导入没有任何错误? 非常感谢您的帮助。

UPDATE1

如果需要,我的应用的代码 init .py:

import logging

import celery
from flask import Flask, render_template_string, render_template
from flask_bootstrap import Bootstrap
from flask_mail import Mail
from flask_security import Security, current_user, auth_required, hash_password, \
    SQLAlchemySessionUserDatastore
from sqlalchemy.exc import SQLAlchemyError

from configmodule import DevelopmentConfig as Config
# from configmodule import TestingConfig as Config
from database import db_session, init_db, engine
from models import User, Role

logging.basicConfig(filename='s10.log', format='%(asctime)s %(message)s', level=Config.LOGGING_LEVEL)

# Create app
app = Flask(__name__)
Bootstrap(app)


@celery.task
def send_flask_mail(msg):
    mail.send(msg)


app.config.from_object(Config())
# app.config.from_envvar()
mail = Mail(app)

# Setup Flask-Security
user_datastore = SQLAlchemySessionUserDatastore(db_session, User, Role)
security = Security(app, user_datastore)


@security.send_mail_task
def delay_flask_security_mail(msg):
    send_flask_mail.delay(msg)


security.send_mail_task(send_flask_mail.delay)


# Create a user to test with
@app.before_first_request
def create_user():
    init_db()
    u = User.query.filter_by(email='test@me.com')
    if not engine.has_table('s10_user'):
        try:
            user_datastore.create_user(email="test@me.com", password=hash_password("password"))
            db_session.commit()
        except SQLAlchemyError as ie:
            logging.exception(ie)


# Views
@app.route('/login')
@auth_required()
def auth_home():
    return render_template_string('Hello {{email}} !', email=current_user.email)


@app.route('/')
def default_home():
    return render_template('base.html')


if __name__ == '__main__':
    try:
        app.run()
        # app.run(host=Config.SERVER_NAME, port=Config.SERVER_PORT, ssl_context='adhoc')
    except Exception as e:
        logging.warning(e)

UPDATE2

关于第二个错误,

警告:(1366,“字符串值不正确:'\ x92 \ xE9t \ xE9)” 第1列的“ VARIABLE_VALUE”列”)

似乎是字符集问题。我的MySql服务器中有以下内容: enter image description here

0 个答案:

没有答案