gpt4 book ai didi

python - 无法使用 REST Framework JWT 进行身份验证

转载 作者:行者123 更新时间:2023-12-01 04:26:27 26 4
gpt4 key购买 nike

我可以成功请求 token ,并将其包含在新请求的 header 中。但是,当我尝试访问受限 View 时,我不断收到AttributeError:'WSGIRequest'对象没有属性'successful_authenticator'以及AttributeError:“模块”对象没有属性“InvalidTokenError”

这是我的虚拟受限 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')

post方法自然不会开始执行,因为身份验证有问题。

以下是在 Silk Profiler 中检查传入请求后的授权 header :

"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
}

我将不胜感激任何帮助,因为我已经在这个看似基本的问题上停留了一段时间。该错误实际上意味着什么?

编辑:原来的问题已解决,如下所示。这是一个非常愚蠢的错误。

最佳答案

事实证明,我只需将我的 PyJWT 安装更新到最新的 1.4.0 版本。

关于python - 无法使用 REST Framework JWT 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33064791/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com