[Fixed]-ImportError: Could not import 'rest_framework_simplejwt.authentication.JWTAuthentication'

18πŸ‘

βœ…

It seems you are confusing two packages. djangorestframework-jwt which you have in your requirements.txt is no longer maintained. It provides the rest_framework_jwt.authentication.JSONWebTokenAuthentication authentication class.

However, the one you are actually using, rest_framework_simplejwt.authentication.JWTAuthentication, comes from the pip package djangorestframework-simplejwt

So you need to update your requirements.txt. Remove djangorestframework-jwt and add djangorestframework-simplejwt

πŸ‘€Bary12

6πŸ‘

for me the djangorestframework-simplejwt upgrade from 4.4.0 to current latest version 4.6.0 fixed the problem.

pip3 install --upgrade djangorestframework-simplejwt
πŸ‘€Ali Aref

5πŸ‘

If anyone still encountering this error, this is the requirements for djangorestframework-simplejwt:

Python (3.6, 3.7, 3.8)
Django (2.0, 2.1, 2.2, 3.0)
Django REST Framework (3.8, 3.9, 3.10)

I downgraded Django & DRF and the problem is solved for me.

pip uninstall django
pip uninstall djangorestframework
pip install --upgrade django==3.0
pip install --upgrade djangorestframework==3.10
pip install djangorestframework-simplejwt
πŸ‘€Jan Franco

1πŸ‘

For me issue solverd by restarting virtual environment

πŸ‘€Fuad Teymurov

0πŸ‘

I encountered same error when attempting to deploy on Heroku

Upon investigating I found 2 issues in my case:

1] requirements.txt –> This file was not updated and therefore β€˜git add’ and β€˜git commit’ did not pickup the new requirement for djangorestframework-simplejwt

So the solution here was to do a fresh pip freeze > requirements.txt, git add/commit and confirm that on Heroku

2] Secondly I found that Heroku was not finding the v4.6.0 which my python3.8 had installed locally. Instead, I had to edit the requirements.txt to v4.4.0 (current on the pypi.org), redo the git add/commit before this problem was resolved

πŸ‘€Sandy

0πŸ‘

If anyone is still running into this issue using VS Code and running their Django app inside a Docker container, I solved the issue by downgrading my Python version to 3.9, instead of 3.10, and then rebuilding my container.

In your Dockerfile make sure the FROM python:3.9 matches the current supported version of python on the docs page: https://django-rest-framework-simplejwt.readthedocs.io/en/latest/index.html , in this case, version 3.9. Mine was set to 3.10 before, which at the time of this writing, isn’t supported. Then re-build your docker image.

docker-compose down

docker-compose up -d --build

Also, if you are using pipenv to manage your packages, change your python version in your Pipfile, python_version = "3.9". Then run pipenv install to install the change.

πŸ‘€Evan Bloemer

0πŸ‘

My issue was also having installed both djangorestframework-jwt and djangorestframework_simplejwt. After unistalling the former my issue was resolved.

πŸ‘€Carla Aluvai

0πŸ‘

You need to restart your machine and install

  • pip install djangorestframework-jwt
  • pip install djangorestframework-simplejwt

please ensure those lib’s install or not

πŸ‘€shine

0πŸ‘

Depleting virtual environment and creating a new one, install the supported version of drf solved this for me

πŸ‘€Jibril14

Leave a comment