Questions & Answers

Could not import 'knox.auth.TokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'

I'm new to Django rest and I'm trying to create a very simple application that allows user to login/sign-up using knox. But as I try to run commands like "python makmigrations" or any other Django related commands, I get this error:

ImportError: Could not import 'knox.auth.TokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'ugettext_lazy' from 'django.utils.trans lation' (C:\Users\user\Desktop\Proj\Server\env\lib\site-packages\django\utils\translation\

Here're parts of my file that I think are related to knox:




AUTH_USER_MODEL = 'app.User'

'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication', ),}
Answers(3) :

After spending hours trying to figure out why this is happening, I realized it's because I'm using Django 4.0!!!!!!

I downgraded to Django 3.2.11 and everything turned out to be ok:)

I could track a new Knox's version on project's github closed issue:

pypi link:

hope it helps.

After searching on this problem because I have it too. I installed pip install django-rest-knox and it works for me.

2023-01-24 00:30:05
Also make sure to use the latest version from django-rest-knox, because earlier versions didn't worked for me with the latest Django.