Не удалось импортировать 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' для настройки API 'DEFAULT_AUTHENTICATION_CLASSES'
Полная ошибка: Не удалось импортировать 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' для настройки API 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: невозможно импортировать имя 'smart_text' из 'django.utils.encoding'
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
}
<
(backend) PS D:\js\backend> pip freeze
asgiref==3.5.1
Django==4.0.4
django-cors-headers==3.11.0
djangorestframework==3.13.1
djangorestframework-jwt==1.11.0
djangorestframework-simplejwt==5.1.0
mysqlclient==2.1.0
PyJWT==1.7.1
pytz==2022.1
sqlparse==0.4.2
tzdata==2022.1
А это pip freeze в виртуальном env:
в середине ошибки он обращается к некоторым строкам в views.py для декораторов:
from http.client import HTTPResponse
from multiprocessing import context
from django.shortcuts import render
from django.http import HttpResponse, Http404, JsonResponse
from .models import Tweet
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import api_view, permission_classes
from rest_framework import status
Я не уверен, что они вообще связаны
'rest_framework_jwt.authentication.JSONWebTokenAuthentication' это обеспечивается djangorestframework-jwt, который больше не поддерживается. Просто удалите его
вместо этого используйте 'rest_framework_simplejwt.authentication.JWTAuthentication'
который приходит из djangorestframework-simplejwt
Ваш 'DEFAULT_AUTHENTICATION_CLASSES' должен выглядеть следующим образом :
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',
),