【发布时间】:2016-01-08 23:14:02
【问题描述】:
我可以成功请求令牌,并将其包含在新请求的标头中。但是,当我尝试访问受限视图时,我不断收到
AttributeError: 'WSGIRequest' object has no attribute 'successful_authenticator'以及
AttributeError: 'module' object has no attribute 'InvalidTokenError'
这是我的虚拟受限视图:
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')
post 方法自然不会开始执行,因为身份验证有问题。
这是在 Silk profiler 中检查后传入请求的 Authorization 标头:
"AUTHORIZATION: JWT iOjE0NDQ1NjQ...."
我的 settings.py 包含以下内容:
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
}
我很感激任何帮助,因为我已经被这个看似基本的问题困住了一段时间。错误的真正含义是什么?
编辑:原来的问题解决了,回答如下。犯了一个非常愚蠢的错误。
【问题讨论】:
标签: python django django-rest-framework jwt