Flask-Session无法从危险状态导入want_bytes

时间:2018-10-19 21:47:34

标签: python flask flask-session

我正在使用Flask-Session,并且最近安装或升级到了危险的1.0.0。现在,我得到了错误ImportError: cannot import name 'want_bytes'。为什么会发生此错误,我该如何解决?

from flask import Flask, session
from flask_session import Session

app = Flask(__name__)
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\flask\cli.py", line 330, in               __call__
    rv = self._load_unlocked()
  File "c:\program files\python36\lib\site-packages\flask\cli.py", line 317, in          _load_unlocked
    self._app = rv = self.loader()
  File "c:\program files\python36\lib\site-packages\flask\cli.py", line 372, in load_app
    app = locate_app(self, import_name, name)
  File "c:\program files\python36\lib\site-packages\flask\cli.py", line 242, in locate_app
    '\n\n{tb}'.format(name=module_name, tb=traceback.format_exc())
flask.cli.NoAppException: While importing "application", an ImportError was raised:

Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\flask\cli.py", line 235, in locate_app
    __import__(module_name)
  File "C:\Program Files\Python36\learningPython\web_CS50\project1\application.py", line 4, in <module>
    from flask_session import Session
  File "c:\program files\python36\lib\site-packages\flask_session\__init__.py", line 16, in <module>
    from .sessions import NullSessionInterface, RedisSessionInterface, \
  File "c:\program files\python36\lib\site-packages\flask_session\sessions.py", line 23, in <module>
    from itsdangerous import Signer, BadSignature, want_bytes
ImportError: cannot import name 'want_bytes'

我对此感到很困惑,却无法在stackoverflow上或与此相关的任何地方找到适用或有用的答案。

2 个答案:

答案 0 :(得分:2)

itsdangerous 1.1.0包含对此的临时修复。您可以升级其危险级别,并立即继续使用Flask-Session。无需固定为itsdangerous == 0.24。


itsdangerous 1.0.0最近发布,删除了非公共顶级进口。 Flask-Session似乎一直在使用这样的导入from itsdangerous import want_bytes

此版本为reported to Flask-Session,希望最终会发布修复程序。

答案 1 :(得分:1)

itsdangerous软件包的文件结构已更改。该函数位于session.py文件中。从以下位置更改导入语句:

from itsdangerous import Signer, BadSignature, want_bytes

from itsdangerous import Signer, BadSignature
from itsdangerous.encoding import want_bytes

为我工作。