. Advertisement .
. Advertisement .
When Do You Get The Error “ImportError: cannot import name ‘json’ from ‘itsdangerous’”?
When you are attempting to deploy the flask app, you may encounter this error:
ImportError: cannot import name 'json' from 'itsdangerous'
Why Do You Get The Error “ImportError: cannot import name ‘json’ from ‘itsdangerous’”?
The issue “ImportError: cannot import name “json” from itsdangerous”” is most frequently noticed while using a Python application and Flask versions 1.1.2 or 1.1.4. The Flask application depends mostly on two packages when it is used: MarkupSafe: Utilizing MarkupSafe helps to reduce the risk of injection attacks by replacing special meaning characters in XML and HTML with text objects. ItsDangerous: Using Data from ItsDangerous is securely signed using cryptographic techniques. Data is compressed, and the integrity and authenticity of each token are verified using timestamps.
As a result, the main reason of the issue “ImportError: cannot import name ‘json’ from itsdangerous” is an update to MarkupSafe:2.1.0 that deleted soft unicode.
How To Solve The Error “ImportError: cannot import name ‘json’ from itsdangerous”?
Solution 1: Update Flask to 2.0+
The simplest solution for you to resolve the error “ImportError: cannot import name ‘json’ from itsdangerous” is updating Flask to 2.0+. Just update Flask to version 2.0+. Versions 2.0.1, 2.0.2, and 2.0.3 are supported. Any of these versions can be used, and they will all correct your problem. Simply do as the following command:
pip install Flask==2.0.1
pip install Flask==2.0.2
pip install Flask==2.0.3
After doing that, your error will be completely resolved.
Solution 2: Downgrade MarkupSafe to version 2.0.1
Downgrading MarkupSafe to version 2.0.1 is also a great way for you to resolve your problem.
The commands to upgrade Flask to version 2.1.2 and downgrade MarkupSafe to version 2.0.1 are listed below:
pip install Flask==1.1.4 pip install markupsafe==2.0.1
Solution 3: Downgrade itsdangerous
Excepting the solutions mentioned above, there is another solution for you to solve the error “ImportError: cannot import name ‘json’ from itsdangerous”. It is dowgrading itsdangerous. Let’s run the following command to do that:
pip install itsdangerous==2.0.1
Solution 4: Utilize this version
You just need to utilize all versions because in our example flask==1.1.4, itsdangerous==1.1.0, and markupsafe==1.1.1 all worked perfectly great. Just run the command below to install this version. Simply execute each command in your terminal one at a time.
pip install flask==1.1.4 pip install itsdangerous==1.1.0 pip install markupsafe==1.1.1
Solution 5: Downgrade Flask
The last solution we suggest you in this blog is downgrading Flask. Let’s downgraded it to 1.1.4 version and after that the error will be fixed. Simply run the following command in your terminal.
pip install flask==1.1.4
All solutions presented above are useful for your error, so let’s apply them to get your desired results. Your error will completely disappear and your program will run well without any errors if you use them.
We hope that you will enjoy our article about the error. With this knowledge, we know that you can fix your issue: “ImportError: cannot import name ‘json’ from itsdangerous” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
→ Solving “ImportError: cannot import name ‘Markup’ from ‘jinja2’”
Leave a comment