ImportError: cannot import name 'TimedJSONWebSignatureSerializer' from 'itsdangerous'
Explains why `from itsdangerous import TimedJSONWebSignatureSerializer` throws ImportError on itsdangerous 2.1+ and how to fix it by switching to URLSafeTimedSerializer or pinning an older version. Use when upgrading itsdangerous or Flask breaks old token code. Not for `No module named 'itsdangerous'`.
ImportError: cannot import name 'TimedJSONWebSignatureSerializer' from 'itsdangerous'
TL;DR: itsdangerous removed TimedJSONWebSignatureSerializer in version 2.1. Replace it with URLSafeTimedSerializer, which does the same timed signed-token job, or pin itsdangerous<2.1 as a stopgap.
ImportError: cannot import name 'TimedJSONWebSignatureSerializer' from 'itsdangerous'The fix
- Replace the import:
from itsdangerous import URLSafeTimedSerializer- Replace usage. Old:
s = TimedJSONWebSignatureSerializer("secret")
token [your value] 1})New:
s = URLSafeTimedSerializer("secret")
token [your value] 1})
data = s.loads(token, max_age=3600)- Verify:
python -c "from itsdangerous import URLSafeTimedSerializer; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=itsdangerous+TimedJSONWebSignatureSerializer'
When this applies
- The import worked before an itsdangerous or Flask upgrade.
pip show itsdangerousreports 2.1 or newer.- Old tutorials or vendored code still reference the JWS serializer names.
When it does NOT apply
- The error is
cannot import name 'json' from 'itsdangerous', which is the sibling 2.1 removal with its own fix. - You actually need JWS/JWT features; then use authlib or PyJWT instead.
Why this happens
The maintainers decided JWS did not belong in itsdangerous and deprecated it in 2.0 with warnings, then deleted it in 2.1. Projects that ignored the deprecation warnings broke on upgrade. URLSafeTimedSerializer is the blessed replacement for timed signed tokens and produces URL-safe strings like the old class did.
Compatibility
itsdangerous 2.1+ removed the class. URLSafeTimedSerializer exists in all 2.x versions.