Upgrading Django to 5.2.7 causing error wth rest_framework_simplejwt as django.utils.timezone is depreciated

I am upgrading my Django project to v5.2.7.

After installing requirements.txt with the upgraded versions of all libraries, I ran the command to validate the code

python manage.py check

But it is throwing error

ImportError: Could not import 'rest_framework_simplejwt.authentication.JWTAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'utc' from 'django.utils.timezone' (...\envs\localenv\Lib\site-packages\django\utils\timezone.py).

Requirements.txt

asgiref==3.8.1
certifi==2023.11.17
Django==5.2.7
django-cors-headers==4.3.1
djangorestframework==3.14.0
mysqlclient==2.2.0
PyJWT==2.8.0
pytz==2023.3
newrelic==9.0.0
djangorestframework_simplejwt==5.2.0
sqlparse==0.4.4

You've upgraded to Django 5.2.7, but django.utils.timezone.utc is deprecated since Django 4.1. Some third-party packages (mostly older versions) still try to import it tho.

Deprecated Use instead
django.utils.timezone.utc datetime.timezone.utc

(I think you should check what upgrading your djangorestframework-simplejwt does)

Find the file (path shown in error):

\env\localenv\Lib\site-packages\rest_framework_simplejwt\tokens.py

Find the line:

from django.utils.timezone import utc

and replace it with:

from datetime import timezone
utc = timezone.utc

This is temporarily fixing the issue

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