importerror: cannot import name ‘json’ from ‘itsdangerous’

importerror_ cannot import name 'json' from 'itsdangerous'

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.

  1. Fix the Flask to the 1.1.4 version
  2. 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
importerror cannot import name 'json' from 'itsdangerous'
importerror cannot import name ‘json’ from ‘itsdangerous’

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.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Abhishek ( Chief Editor) , a data scientist with major expertise in NLP and Text Analytics. He has worked on various projects involving text data and have been able to achieve great results. He is currently manages Datasciencelearner.com, where he and his team share knowledge and help others learn more about data science.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner