django - 如果在使用客户端凭据的 Oauth2 请求期间用户为无,则 Django Rest Framweork 中的节流
问题描述
我正在使用 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()
你能帮我解决这个问题吗?
谢谢 !
解决方案
推荐阅读
- google-cloud-dataflow - 组合 KV 对的 PCollection 时,如何访问 CombinerFn 子类中的密钥?
- vb.net - 如何在不分散现有数据的情况下将 csv 数据合并到 datagridview 中
- sql - Oracle SQL - 没有计数结果时返回日期记录
- python - select specific face from multiple detected faces inside image from Haar-cascade in python
- javascript - 检查嵌套对象中是否存在键
- django - 如何在 AbstractUser 模型中修改电子邮件字段,以便需要电子邮件
- python-3.x - 如何获得每个频段的平均fft值?
- javascript - NodeJS、sqlite3 和 WHERE IN 参数
- ubuntu - 在 Ubuntu 18.04 - 内核 4.18 中未调用 Netfilter 挂钩
- python-3.x - 通过分类字段创建连续字段的密度图