The importerror: cannot import name ‘json’ from ‘itsdangerous’ error occurs because of incompatibility between Flask and itsdangerous package. Most developers get this error while running the flask application using docker. More specifically Flask module has two dependencies one with MarkupSafe and itsdangerous. Here this itsdangerous package is useful in protecting session cookies. It maintains data integrity. Well In this article, we will see the best and easiest way to fix this error.
Importerror: cannot import name ‘json’ from ‘itsdangerous’ ( Cause & Fix) –
This is an intermediate issue with some of the Flask versions like (Flask version 1.1.2 or Flask version 1.1.4). Here underline Flask version 1.1.2 creates an incompatibility with MarkupSafe:2.1.0 + versions version error due to migration of soft_unicode.
There are multiple ways to fix this error. Firstly, I will suggest upgrading the Flask.
Solution 1: Upgrading Flask to the Latest version –
Use any of the commands to upgrade the flask module to the latest version.
Command 1 –
pip install flask
Command 2 –
conda install -c anaconda flask
Both commands will upgrade the underline flask version to the latest.
Solution 2: Adjusting the version to a specific –
If you want to solve this Importerror in this way, Firstly understand the fully compatible set for it.
- Fix the Flask to the 1.1.4 version
- Install the markupsafe version 2.0.1
This is a compatible pair of versions. You will get rid of this error.
Solution 3: Fixing the version for itsdangerous==2.0.1 –
Still, if you do not want to upgrade the flask, The only solution is to fix the version ( Downgrading ) of iitsdangerous to 2.0.1 because it is compatible with Flask 1.1.2 version. This is the cheapest solution but sometimes makes things more complex. I mean it can cause incompatibility with another module.
Here is the command for downgrading itsdangerous to 2.0.1.
pip install itsdangerous==2.0.1

Hope you got the solution now.
Thanks
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.