maxcountryman/flask-bcrypt

ImportError: cannot import name 'gen_salt' from partially initialized module 'werkzeug.security'

ep4sh opened this issue · 2 comments

ep4sh commented

Hey guys,

Simply installed flask-bcrypt as per the documentation, but getting floating bug (run several times and it failed unpredicatable):

(venv)  courses (master) ✗ flask run --host=0.0.0.0
 * Serving Flask app "main.py" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "/home/ep4sh/python/courses/venv/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/flask/cli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/flask/cli.py", line 852, in run_command
    run_simple(
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/werkzeug/serving.py", line 965, in run_simple
    from .debug import DebuggedApplication
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/werkzeug/debug/__init__.py", line 28, in <module>
    from ..security import gen_salt
ImportError: cannot import name 'gen_salt' from partially initialized module 'werkzeug.security' (most likely due to a circular import) (/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/werkzeug/security.py)
(venv)  courses (master) ✗ flask run --host=0.0.0.0
 * Serving Flask app "main.py" (lazy loading)
 * Environment: development
 * Debug mode: on
Traceback (most recent call last):
  File "/home/ep4sh/python/courses/venv/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/flask/cli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/flask/cli.py", line 852, in run_command
    run_simple(
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/werkzeug/serving.py", line 965, in run_simple
    from .debug import DebuggedApplication
  File "/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/werkzeug/debug/__init__.py", line 28, in <module>
    from ..security import gen_salt
ImportError: cannot import name 'gen_salt' from partially initialized module 'werkzeug.security' (most likely due to a circular import) (/home/ep4sh/python/courses/venv/lib/python3.9/site-packages/werkzeug/security.py)
(venv)  courses (master) ✗ flask run --host=0.0.0.0
 * Serving Flask app "main.py" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 113-244-799

in my app module:

  2 from flask import Flask                                                         
  3 from flask_bcrypt import Bcrypt                                                                                            
  ..........
 11 flask_bcrypt = Bcrypt(app)                                                                                                       

list of packages:

(venv)  courses (master) ✗ pip list
Package          Version
---------------- -------
bcrypt           3.2.0
cffi             1.14.5
click            7.1.2
dnspython        2.1.0
email-validator  1.1.2
Flask            1.1.2
Flask-Bcrypt     0.7.1
Flask-Login      0.5.0
Flask-SQLAlchemy 2.4.4
Flask-WTF        0.14.3
idna             3.1
itsdangerous     1.1.0
Jinja2           2.11.3
MarkupSafe       1.1.1
pip              21.0.1
pycparser        2.20
python-dotenv    0.15.0
setuptools       49.2.1
six              1.15.0
SQLAlchemy       1.3.23
Werkzeug         1.0.1
WTForms          2.3.3

Please suggest any ideas on how to fix it =)

Thanks in advance,
cheers

Version 1.0.0 was released today which should fix this.