Djangorestframework-simplejwt: ImportError: cannot import name 'InvalidTokenError'.

Created on 14 Sep 2018  路  9Comments  路  Source: jazzband/djangorestframework-simplejwt

I am getting this error:

ImportError: Could not import 'rest_framework_simplejwt.authentication.JWTAuthentication' for 
API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 
'InvalidTokenError'.

image

any idea why?

Most helpful comment

ok got it, apparently i had https://pypi.org/project/jwt/ installed which is creating the same module names as https://pyjwt.readthedocs.io/en/latest/ does.
pip uninstall both, install pyjwt -> your good to go

All 9 comments

did you find a solution? stumbling across the same thing after a new setup.

@SMaurischat I just switched to:

Django==2.1.1
djangorestframework==3.8.2
djangorestframework-jwt==1.11.0

and it worked.

nope, that did not help me :)
Thanks anyhow for the quick reply!

ok got it, apparently i had https://pypi.org/project/jwt/ installed which is creating the same module names as https://pyjwt.readthedocs.io/en/latest/ does.
pip uninstall both, install pyjwt -> your good to go

ah nice, glad you solved it!

djangorestframework-jwt==1.11.0

for me its not......

It's a different issue. There were two packages with the same name that caused this issue.

your machine must be confused about which framework used pyjwt or djangorestframework-jwt so first uninstall pyjwt.
first, uninstall Django, Django rest framework-jwt, djangorestframework, and then install specific this version
Django==2.1.1,
djangorestframework==3.8.2,
djangorestframework-simplejwt==4.4.0,
for me, it's worked

make sure you have imported 'from rest_framework_simplejwt.authentication import JWTAuthentication' in your settings.py

Was this page helpful?
0 / 5 - 0 ratings