Reputation: 722
I can successfully request a token, and include it in the header of the new request. However, when I try to access restricted views, I keep getting
AttributeError: 'WSGIRequest' object has no attribute 'successful_authenticator'
as well as
AttributeError: 'module' object has no attribute 'InvalidTokenError'
Here's my dummy restricted view:
class RestrictedView(APIView):
permission_classes = (IsAuthenticated, )
authentication_classes = (JSONWebTokenAuthentication, )
def post(self, request):
response_data = json.dumps({"authenticated": "mooh"})
return HttpResponse(response_data, content_type='application/json')
The post method naturally doesn't start executing, since there's a problem with the authentication.
Here is the Authorization header of the incoming request after checking it in the Silk profiler:
"AUTHORIZATION: JWT iOjE0NDQ1NjQ...."
My settings.py contains the following:
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',
),
'FORM_METHOD_OVERRIDE': None,
'FORM_CONTENT_OVERRIDE': None,
'FORM_CONTENTTYPE_OVERRIDE': None
}
I'd appreciate any help, as I've been stuck on this seemingly basic issue for a while. What does the error actually mean?
Edit: The original problem is solved, as answered below. Quite a silly mistake to make.
Upvotes: 2
Views: 1941
Reputation: 722
It turned out that I just had to update my PyJWT
installation to the latest, 1.4.0
version.
Upvotes: 2