[Fixed]-Django Rest Framework {"detail":"Authentication credentials were not provided."}

22👍

In my case token authentication was working fine on development server and not on Apache. The reason was exactly the missing WSGIPassAuthorization On

http://www.django-rest-framework.org/api-guide/authentication/#apache-mod_wsgi-specific-configuration

6👍

see your settings.py, if you have

'DEFAULT_PERMISSION_CLASSES': (
    'rest_framework.permissions.IsAuthenticated',
),

in REST_FRAMEWORK like this, it will Authenticate each time when you post.

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
    'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.TokenAuthentication',
)}

so, delete it.

0👍

In my case, I used a permissions.IsAuthenticatedOrReadOnly permission class in my viewset, but sending a post request without login:

class MemberViewSet(viewsets.ModelViewSet):

    queryset = Member.objects.all()
    serializer_class = MemberSerializer

    permission_classes = (
        permissions.IsAuthenticatedOrReadOnly,
    )

    @list_route(methods=['post'])
    def check_activation_code(self, request):
        # my custom action which do not need login
        # I met the error in this action
        do_something()

So the permission checking for that permission class is failed.

Everything goes well after I remove the IsAuthenticatedOrReadOnly permission class.

Leave a comment