Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting this error rest_framework.request.WrappedAttributeError

I am trying to upgrade my django 1.9 to django 2.0. It is working fine for GET() but I am getting error in POST(). My views.py is:-

class AccountInfoUpdate(APIView):
    authentication_classes = [IsAuthenticated]

    def post(self, request):
        user = request.user
        user_profile = UserProfile.objects.get(user=user)
        name = False
        contact = False
        if "name" in request.data:
            user_profile.name = request.data.get('name')
            user_profile.save()
            name = True
        if "contact" in request.data:
            user_profile.contact = request.data.get('contact')
            user_profile.save()
            contact = True

        if user_profile.affiliate_code is not None and (name or contact):
            result = service.update_affiliate(user_profile.affiliate_code, name=user_profile.name,
                                                   contact=user_profile.contact)

        return Response({'Message': 'Account info updated successfully!'})

I am getting this error:-

user_auth_tuple = authenticator.authenticate(self)
rest_framework.request.WrappedAttributeError: 'IsAuthenticated' object has no attribute 'authenticate'

If I removed or comment 'rest_framework.authentication.SessionAuthentication', from REST_FRAMEWORK then I am getting this error CSRF Failed: CSRF token missing or incorrect.

I tried permission_classes = [IsAuthenticated] and did fallow on Postman but still getting same error.

enter image description here

enter image description here

enter image description here

like image 840
Razia Khan Avatar asked Sep 15 '25 16:09

Razia Khan


1 Answers

IsAuthenticated is a Permission Class not an Authentication class. So it should be as


class AccountInfoUpdate(APIView):
    permission_classes = [IsAuthenticated]
    # your code



UPDATE-1
How to resolve CSRF Failed error

1. Open a new tab in POSTMAN
POSTMAN Screenshot 2. Provide URL(1) 3. Go to Authorization tab(2) and setect Basic Auth then provide your username and password
4. Then go to Body tab, and enter your JSON payload. 5. Hit send button. There you go

like image 166
JPG Avatar answered Sep 18 '25 10:09

JPG