python - DRF API 端点获取 "Authentication credentials were not provided"

标签 python django django-rest-framework postman

我正在使用 DRF 构建一些 API 端点。这是代码片段。

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

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

我尝试通过 postman 基本身份验证调用 API。但它总是返回“未提供身份验证凭据”。 这是身份验证配置的代码片段。

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

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

最佳答案

确保您使用的凭据是正确的,并且允许用户在两​​种权限级别下进行访问

来自docs (强调我的)

If any permission check fails an exceptions.PermissionDenied or exceptions.NotAuthenticated exception will be raised, and the main body of the view will not run.

关于python - DRF API 端点获取 "Authentication credentials were not provided",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50648521/

相关文章:

python - Django update_or_create(获取部分)使用相关对象作为 kwarg

python - django 休息框架断言错误

python - 处理选定行时避免 pandas 数据框中的 for 循环

python - 使用keras同时训练两个网络

python - ZODB 无法提交

python - Django - 用户定义的查询集过滤

python - float 在预定义函数中的行为不像 float

python - Django + fcgi = 未显示对 views.py 的新编辑

python - DRF 在序列化器 update() 调用中更新 ManyToMany

Python Django REST 调用返回对象编号而不是对象名称