How to Fix: Cannot import safe_str_cmp from Werkzeug
Hello! This page explains how to fix "ImportError: cannot import name 'safe_str_cmp' from werkzeug.security" caused by the latest Werkzeug version - v2.1.0 (at the time this article is written).
For newcomers, Werkzeug, the core dependency of Flask, is a comprehensive WSGI web application library. The mentioned error is bumped when the used version of Werkzeug is v2.1.0 (or greater).
β¨ Werkzeug Update History
π v2.0.0
pbkdf2_hex
,pbkdf2_bin
, andsafe_str_cmp
are deprecated.hashlib
andhmac
provide equivalents.
π v2.1.0
Remove thepbkdf2_hex
,pbkdf2_bin
, andsafe_str_cmp
functions. Use equivalents inhashlib
andhmac
modules instead.
β¨ How to Fix
Freeze the Werkzeug
Β to the latest stable version prior to v2.1.0. The recommended version is Werkzeug==2.0.3.
β¨Sample Project
To see this hotfix in action, feel free to check this sample project saved on Github (MIT License)
βFlask Datta Able - open-source Flask Starter generated by AppSeed
- π Datta Able Flask - Source Code
- π Datta Able Flask - LIVE deployment