Skip to content
Advertisement

ImportError: Could not import ‘rest_framework_simplejwt.authentication.JWTAuthentication’

I am trying to deploy a django app on GCP but when i try to make migrations it gives me this error:

ImportError: Could not import ‘rest_framework_simplejwt.authentication.JWTAuthentication’ for API setting ‘DEFAULT_AUTHENTICATION_CLASSES’. ModuleNotFoundError: No module named ‘rest_framework_simplejwt’.

Settings.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated'
    ],
'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ]
}

SIMPLE_JWT = {
    'ALGORITHM': 'HS256',
    'SIGNING_KEY': SECRET_KEY,
    'VERIFYING_KEY': None,
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=800),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=2),
}
OAUTH2_PROVIDER = {
        'ACCESS_TOKEN_EXPIRE_SECONDS': 60 * 15,
        'OAUTH_SINGLE_ACCESS_TOKEN': True,
        'OAUTH_DELETE_EXPIRED': True
 }

requirements.txt

django-cors-headers
pyjwt
djangorestframework
djangorestframework-jwt==1.11.0

What is it that I am missing ?

UPDATE I installed rest_framework_simplejwt and now the error shifted to :

No module named ‘rest_framework_simplejwt.tokens’

Advertisement

Answer

It seems you are confusing two packages. djangorestframework-jwt which you have in your requirements.txt is no longer maintained. It provides the rest_framework_jwt.authentication.JSONWebTokenAuthentication authentication class.

However, the one you are actually using, rest_framework_simplejwt.authentication.JWTAuthentication, comes from the pip package djangorestframework-simplejwt

So you need to update your requirements.txt. Remove djangorestframework-jwt and add djangorestframework-simplejwt

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement