miguelgrinberg/microblog

AttributeError: module 'hashlib' has no attribute 'scrypt'

Opened this issue · 1 comments

(venv) rayhan@Rayhans-MacBook-Air microblog % flask shell
Python 3.9.6 (default, May 7 2023, 23:32:44)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
App: app
Instance: /Users/rayhan/microblog/instance

from werkzeug.security import generate_password_hash
hash = generate_password_hash('foobar')
Traceback (most recent call last):
File "", line 1, in
File "/Users/rayhan/microblog/venv/lib/python3.9/site-packages/werkzeug/security.py", line 107, in generate_password_hash
h, actual_method = _hash_internal(method, salt, password)
File "/Users/rayhan/microblog/venv/lib/python3.9/site-packages/werkzeug/security.py", line 42, in _hash_internal
hashlib.scrypt(
AttributeError: module 'hashlib' has no attribute 'scrypt'

This happens because the Python that ships with macOS is missing the scrypt module.

You have two possible solutions:

  • Install a different Python, such as one from python.org or homebrew.
  • To keep using the macOS Python, you can add a method='pbkdf2' argument to the call to generate_password_hash().