1

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
2
  • Find the line: from django.utils.timezone import utc and replace it with: from datetime import timezone utc = timezone.utc Commented Nov 6 at 10:26
  • Yes, but issue is should we manually change the file on server? Commented Nov 6 at 10:54

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

Comments

-4

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

4 Comments

So can library file be updated manually?
Yes possible but you have to fix every time you share code on different machine
this is not right approach, just upgrade the package to the version which work well with 5.2.7. dont use this
This won't work when you run the code on another machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.