“detail”:“未提供身份验证凭据。”

时间:2018-06-19 07:35:46

标签: authentication django-rest-framework postman

``我正在尝试在我的Django Rest Framework应用程序中实现令牌认证。我能够从django服务器接收令牌但是当我发送带有'Authorization'标头的请求时,我收到以下错误:

{     “detail”:“未提供身份验证凭据。” }

我还检查了request.META,并且没有名为“HTTP_AUTHORIZATION”的密钥。我在开发服务器上运行我的django应用程序。

Views.py

# Create your views here.
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.decorators import api_view,authentication_classes,permission_classes
from django.contrib.auth.decorators import permission_required,login_required
import google.cloud.storage
import uuid
import psycopg2


@api_view(['GET'])
@authentication_classes((SessionAuthentication, BasicAuthentication))
@permission_classes((IsAuthenticated,))
def auth_test(request):
    return Response("it's great to have you here with token auth!!")

@api_view(['GET'])
def free_test(request):
    #print(request.META['HTTP_AUTHORIZATION'])
    return Response("entry without token auth !!")

django服务器没有收到我的授权凭据的原因是什么?

POSTMAN SCREENSHOT我已经通过了授权标题

screenshot

1 个答案:

答案 0 :(得分:1)

您正尝试使用Map(key2 -> List(val1, val2, val3), key1 -> List(val1, val2)) 身份验证方法访问您的视图,Token中未提及您。请尝试以下代码

authentication_classes