Could not import 'knox.auth.TokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'
Question:
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 manage.py 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:UsersuserDesktopProjServerenvlibsite-packagesdjangoutilstranslation__init__.py).
Here’re parts of my settings.py file that I think are related to knox:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'knox',
'corsheaders',
'app',]
AUTH_USER_MODEL = 'app.User'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication', ),}
Answers:
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:)
After searching on this problem because I have it too.
I installed pip install django-rest-knox
and it works for me.
I could track a new Knox’s version on project’s github closed issue:
https://github.com/James1345/django-rest-knox/issues/260#issuecomment-1026060106
pypi link:
https://pypi.org/project/django-rest-knox/4.2.0/
hope it helps.
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 manage.py 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:UsersuserDesktopProjServerenvlibsite-packagesdjangoutilstranslation__init__.py).
Here’re parts of my settings.py file that I think are related to knox:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'knox',
'corsheaders',
'app',]
AUTH_USER_MODEL = 'app.User'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication', ),}
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:)
After searching on this problem because I have it too.
I installed pip install django-rest-knox
and it works for me.
I could track a new Knox’s version on project’s github closed issue:
https://github.com/James1345/django-rest-knox/issues/260#issuecomment-1026060106
pypi link:
https://pypi.org/project/django-rest-knox/4.2.0/
hope it helps.