【问题标题】:DRF API endpoint getting "Authentication credentials were not provided"DRF API 端点获取“未提供身份验证凭据”
【发布时间】:2018-11-11 21:31:05
【问题描述】:

我正在使用 DRF 构建一些 API 端点。这是代码sn-p。

class ReportsDashboardView(views.APIView):
 permission_classes = (
        IsAuthenticated, IsActiveUser,
 )

 def get(self, request, format=None):
  ...

我尝试通过邮递员基本身份验证调用 API。但它总是返回“未提供身份验证凭据”。 这是验证配置的代码sn-p。

REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'] = (
    'rest_framework.authentication.SessionAuthentication',
    'rest_framework.authentication.TokenAuthentication',
    'rest_framework.authentication.BasicAuthentication',
)

我不确定为什么基本身份验证(用户名、密码)对我不起作用。 这是你以前遇到过的吗?你愿意帮助我吗?

【问题讨论】:

  • 你能说明IsActiveUser是如何定义的吗?
  • 是的。当然。我已经定义了。
  • 您还需要显示IsActiveUser 权限类的代码

标签: python django django-rest-framework postman


【解决方案1】:

确保您使用的凭据是正确的,并且用户在两个权限类别下都被允许访问

来自docs(强调我的)

如果 any 权限检查失败 exceptions.PermissionDenied 或 exceptions.NotAuthenticated 将引发异常,并且主要 视图主体不会运行。

【讨论】:

    猜你喜欢
    • 2019-04-26
    • 2020-01-11
    • 2019-08-09
    • 2022-01-10
    • 2016-03-17
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    相关资源
    最近更新 更多