django-rest-framework-jwt icon indicating copy to clipboard operation
django-rest-framework-jwt copied to clipboard

Issue with importing JWT for Authentication after following the tutorial

Open Miguelme opened this issue 8 years ago • 9 comments

I'm getting the following error after following the tutorial. It's worth noting that I am only getting this error in heroku and not local.

ImportError: Could not import 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named rest_framework_jwt.authentication.

The error appears to be with importing in here:


REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),
}

It's in the requirements.txt:

dj-static==0.0.6
Django==1.9.2
django-cors-headers==1.1.0
djangorestframework==3.3.3
djangorestframework-jwt==1.8.0
PyJWT==1.4.1
static3==0.7.0

Any help will be really appreciated.

Thanks in advance.

Miguelme avatar Jul 13 '16 22:07 Miguelme

In the INSTALL_APPS, make sure you included 'auth_jwt" entry.

whippersnapper avatar Sep 28 '16 01:09 whippersnapper

@whippersnapper adding 'auth_jwt' does not solve the problem. Does anyone know what module to add to installed apps so that 'rest_framework_jwt' becomes available? Thanks

NjengaSaruni avatar Apr 08 '17 08:04 NjengaSaruni

In my case the problem was I had the wrong virtualenv activated. For rest_framework_jwt to be available, all you need to do is pip install djangorestframework-jwt into your virtual environment. Your interpreter will find it just fine.

NjengaSaruni avatar Apr 08 '17 08:04 NjengaSaruni

None of the above solutions works for me. Any other ideas?

isidroc avatar Mar 23 '18 17:03 isidroc

Try adding 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.AllowAny', ),

in REST_FRAMEWORK. It worked fine for me

pradumangoyal avatar Jun 12 '18 15:06 pradumangoyal

djangorestframework-jwt is a seperate package.pip install djangorestframework-jwt should solve the problem.

vishnu-chalil avatar Jul 17 '18 07:07 vishnu-chalil

I get the same issue, tried all above solutions given, nothing worked.., any help!! Thanks in advance.

anonyxhappie avatar Jul 31 '18 17:07 anonyxhappie

I fixed it by running pipenv shell before running the server

ghost avatar Aug 18 '18 11:08 ghost

@warlordzephyr , would please provide more descriptiin and the steps you used?

huxaiphaer avatar Aug 28 '18 19:08 huxaiphaer