pallets-eco / flask-security

Quick and simple security for Flask applications
MIT License
1.63k stars 513 forks source link

ImportError: cannot import name '_request_ctx_stack' from 'flask' #880

Closed princerb closed 7 months ago

princerb commented 7 months ago

🔰 I just applied a quick tutorial code to my Flask app.

# ...
app = Flask(__name__)

user_datastore = SQLAlchemySessionUserDatastore(db.session, UserModel)
security = Security(app, user_datastore)
# ...

🚫 Then this error occured:

    ...
    from flask import _request_ctx_stack
ImportError: cannot import name '_request_ctx_stack' from 'flask' (C:\myprojectpathwashere\.venv\Lib\site-packages\flask\__init__.py)

I think it is due to the version of Flask. I don't want to downgrade my Flask version, but I guess I have to.

🖥️ Details:

(.venv) C:\myprojectpathwashere>py -V -V
Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)]

(.venv) C:\myprojectpathwashere>pip list
Package           Version
----------------- -------
alembic           1.12.1
Babel             2.13.1
blinker           1.7.0
click             8.1.7
colorama          0.4.6
Flask             3.0.0   <<<
Flask-BabelEx     0.9.4   <<<
Flask-Login       0.6.3
Flask-Mail        0.9.1
Flask-Principal   0.4.0
Flask-Security    3.0.0   <<<
Flask-SQLAlchemy  3.1.1
Flask-WTF         1.2.1
greenlet          3.0.1
itsdangerous      2.1.2
Jinja2            3.1.2
Mako              1.3.0
MarkupSafe        2.1.3
passlib           1.7.4
pip               23.3.1
setuptools        65.5.0
speaklater        1.3
SQLAlchemy        2.0.23
typing_extensions 4.8.0
Werkzeug          3.0.1
WTForms           3.1.1
jwag956 commented 7 months ago

As noted in 'code' section of this repo - Flask-Security isn't maintained - please consider https://github.com/Flask-Middleware/flask-security (Yes - I maintain it).

princerb commented 7 months ago

Oh, okay I can see, thanks