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.
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.
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.
If you want to solve this Importerror in this way, Firstly understand the fully compatible set for it.
This is a compatible pair of versions. You will get rid of this error.
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