Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'generate_password_hash'

from flask import jsonify
from flask import flash, request
from werkzeug import generate_password_hash, check_password_hash

Error Please help me to fix these issues I have tried with pip install Werkzeug But not working

Traceback (most recent call last): File "server.py", line 6, in from werkzeug import generate_password_hash, check_password_hash ImportError: cannot import name 'generate_password_hash'

like image 618
karthick Murugesan Avatar asked May 01 '20 07:05

karthick Murugesan


People also ask

What are the main reasons for importerror cannot import name?

Name error is raised when the system cannot identify the variables used. So, today in this article, we have seen the main reasons for ImportError: Cannot Import Name. We have seen the concept of circular dependency and how it affects our code.

What if the imported module is not imported?

The imported module is not imported. The imported module is not created. Module or Class names are misspelled. Or, the imported class is in circular dependency. There may be more scenarios in which the importerror occurs. But in this article, we will only focus on the last one, i.e.,

What happened to generate_password_hash in Werkzeug?

DeprecationWarning: The import 'werkzeug.generate_password_hash' is deprecated and will be removed in Werkzeug 1.0.

How to fix “Python is unable to import imagetk” error?

Here, the error occurs as Python is unable to import ImageTK. Now, the reason behind the error is unknown, but you can solve it by importing them separately using the following command. Check the __init__.py at root dir. Openpyxl read this information from the .constrants.JSON file.


Video Answer


2 Answers

You can try

from werkzeug.security import generate_password_hash, check_password_hash

or check the version of werkzeug installed in your system. Those functions are available for version 1.0.x

like image 180
ilanos Avatar answered Oct 22 '22 00:10

ilanos


Those functions were deprecated for a while and now they are moved to werkzeug.security


DeprecationWarning: The import 'werkzeug.generate_password_hash' is deprecated and will be removed in Werkzeug 1.0. Use 'from werkzeug.security import generate_password_hash' instead.
  from werkzeug import generate_password_hash, check_password_hash
DeprecationWarning: The import 'werkzeug.check_password_hash' is deprecated and will be removed in Werkzeug 1.0. Use 'from werkzeug.security import check_password_hash' instead.
  from werkzeug import generate_password_hash, check_password_hash
like image 22
RafalS Avatar answered Oct 21 '22 23:10

RafalS