admin管理员组文章数量:1415673
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?
版权声明:本文标题:python - Import Error: module does not define a "CustomJWTAuthentication" attributeclass - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745240072a2649275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论