Serverside debug Django "Not Acceptable"

469 Views Asked by At

When calling an URL on my Django API it returns:

[04/Sep/2021 08:14:47] WARNING [django.request:224] Not Acceptable: /api/calendar/test.ics

Calling the same URL from PostMan (or curl) returns a simple iCal file so the URL is valid and returning.

What I found was that the cause is the "Accept" headers sent by the client. The problem is that the request never actually hits my view so I cannot inspect request.META for the value of the received accept header.

How can I discover, serverside, what headers were sent and what their values are?

1

There are 1 best solutions below

0
DIJ On

Still not sure what is going on. But, If you want to inspect the headers, you can define add the dispatch function to your class based view, something like:

class MyView(APIView):
    def dispatch(self, request, *args, **kwargs):
        logger.debug("{}".format(request.META))

        if request.method == 'GET':
            return self.get(request, *args, **kwargs)
        elif request.method == 'POST':
            return self.post(request, *args, **kwargs)

    def get(self, request):

    def post(self, request):

The strange thing is, now with the dispatch function added to the view, the request is somehow accepted.