0

我正在使用 Django Rest Framework 和 Django OAuth Toolkit 来允许外部组织请求端点。

我正在使用 Crendentials Client 授权类型来询问访问令牌。在此处输入图像描述

当我尝试请求我的端点时,出现此错误:'NoneType' 对象没有属性'is_authenticated'。AnonThrottleClass 的 get_cached_key 函数中引发了异常。

实际上 request.user 是 None with Client Credentials,所以这个函数不能通过。

这是我的观点:

class StudentViewSet(
mixins.CreateModelMixin,
mixins.UpdateModelMixin,
mixins.RetrieveModelMixin,
mixins.ListModelMixin,
mixins.DestroyModelMixin,
viewsets.GenericViewSet,):

serializer_class = StudentSerializer
authentication_classes = (OAuth2Authentication,)
permission_classes = (TokenHasScope,)
required_scopes = [
    oauth2_settings.READ_SCOPE,
    oauth2_settings.WRITE_SCOPE,
]
schema = is_schema_for_open_api_doc(True)
queryset = Student.objects.all()

你能帮我解决这个问题吗?

谢谢 !

4

0 回答 0