ImportError: cannot import name 'TimedJSONWebSignatureSerializer' from 'itsdangerous'

Question:

I’m running a flask app using itsdangerous python package in AWS EC2 instance.

Traceback (most recent call last):
  File "run.py", line 4, in <module>
    app = create_app()
  File "/home/ubuntu/RHS_US/application/portal/__init__.py", line 29, in create_app
    from portal.users.routes import users
  File "/home/ubuntu/RHS_US/application/portal/users/routes.py", line 7, in <module>
    from portal.models import User
  File "/home/ubuntu/RHS_US/application/portal/models.py", line 7, in <module>
    from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
ImportError: cannot import name 'TimedJSONWebSignatureSerializer' from 'itsdangerous' (/home/ubuntu/.local/lib/python3.7/site-packages/itsdangerous/__init__.py)

Any resolution for this?

Answers:

In the latest version of itsdangerous, TimedJSONWebSignatureSerializer is no longer available. Try this instead. It worked for me. from itsdangerous import URLSafeTimedSerializer as Serializer

Answered By: user19844617

Itsdangerous is a very common and popular package used for serialization in other packages and apps.
To fix this:

  1. Upgrade your Flask to the newest version — pip install flask –upgrade
  2. Downgrade itsdangerous to version 2.0.1 — pip install itsdangerous==2.0.1
  3. After downgrading it, install email_validator again to make the issue fixed — pip install email_validator

I hope this fixes the issue for you. Happy Coding

Answered By: Ajayi Oluwaseyi

First make sure to re-install and update itsdangerous.
pip install -U itsdangerous

Then what you want to do is

 from itsdangerous.url_safe import URLSafeTimedSerializer as Serializer

This works well.

Answered By: Hilario Nengare
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.