"detail": "Authentication credentials were not provided."

5,887 views
Skip to first unread message

steve malise

unread,
May 27, 2015, 3:22:04 AM5/27/15
to django-res...@googlegroups.com
view.py:
@csrf_exempt
@permission_classes((AllowAny, ))
@api_view(['GET', 'POST'])
def testing(request):
    if request.method == 'GET':
        permission_classes = (permissions.IsAuthenticatedOrReadOnly,IsOwnerOrReadOnly)
        snippets = Temperature.objects.all()
        serializer = serializers.TemperatureSerializer(snippets, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
           permission_classes = (permissions.IsAuthenticatedOrReadOnly,IsOwnerOrReadOnly)
        serializer = serializers.TemperatureSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

url.py:
urlpatterns = [
    url(r'^$', views.testing),
]

setting.py:

REST_FRAMEWORK = {
   'DEFAULT_AUTHENTICATION_CLASSES': (
       'rest_framework.authentication.TokenAuthentication',
       'rest_framework.authentication.SessionAuthentication',
       'rest_framework.authentication.BasicAuthentication',

   ),
   'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAdminUser',
        'rest_framework.permissions.IsAuthenticated',
        'rest_framework.permissions.AllowAny',
   ),
   'PAGINATE_BY': 10,
}

please help,i have googled this,tryed to read up on Django REST framework permissions,and still i didn't find an answer.
I don't know what is wrong.
Please help me about this error

I get something like this:
"
HTTP 401 Unauthorized
WWW-Authenticate: Token
Allow: GET, POST, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Authentication credentials were not provided."
}
"

Carlton Gibson

unread,
May 27, 2015, 5:46:22 AM5/27/15
to django-res...@googlegroups.com
Hi Steve,


On Wednesday, 27 May 2015 09:22:04 UTC+2, steve malise wrote:
"
HTTP 401 Unauthorized
WWW-Authenticate: Token
Allow: GET, POST, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Authentication credentials were not provided."
}
"

Are you actually setting the credentials when you make the request? You're wanting to use token authorization — how are you setting that?  

Dmitry Semenov

unread,
Jun 9, 2015, 9:39:08 PM6/9/15
to django-res...@googlegroups.com
You should supply 
Header:

Authorizaton = token 254a5298684bc4a7caa85f4f28fec35152a5af9f

(don't forget token prefix in value)
Reply all
Reply to author
Forward
0 new messages