Import Error: module does not define a "CustomJWTAuthentication" attribute/class

I'm building a REST Auth API with Django/DRF.

All of a sudden when I start working today, I'm getting this error message in my cli:

ImportError: Could not import 'users.authentication.CustomJWTAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: Module "users.authentication" does not define a "CustomJWTAuthentication" attribute/class.

This is my REST_FRAMEWORK config in settings.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'users.authentication.CustomJWTAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ],
    ...
}

This is my /users/authentication.py, which has the CustomJWTAuthentication class:

from django.conf import settings
from rest_framework_simplejwt.authentication import JWTAuthentication

class CustomJWTAuthentication(JWTAuthentication):
    def authenticate(self, request):
        try:
            header = self.get_header(request)

            if header is None:
                raw_token = request.COOKIES.get(settings.AUTH_COOKIE)
            else:
                raw_token = self.get_raw_token(header)

            if raw_token is None:
                return None

            validated_token = self.get_validated_token(raw_token)

            return self.get_user(validated_token), validated_token
        except:
            return None

I'm running Python v3.12, Django v4.2, DRF v3.14 and DRF SimpleJWT v5.4 on Ubuntu 24 in a venv.

I have no idea why this is happening all of a sudden?

Вернуться на верх