Search code examples
pythondjangoposttwiliocsrf

CSRF Tag Still Rejecting Twilio Requests


I'm writing a simple view which takes in a Twilio SMS request and returns a simple SMS, based on this tutorial.

For some reason, requests still are met with 403 Forbidden:

Forbidden (CSRF cookie not set.): /haul/response
[20/Jul/2017 17:39:42] "POST /haul/response HTTP/1.1" 403 2857`

My view is as follows:

from django.http import HttpResponse
from twilio.rest import Client
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def response(request):
    twiml = '<Response><Message>Test</Message></Response>'
    return HttpResponse(twiml, content_type='text/xml')

I know this isn't a server issue since I experience the same results on both my production server and local machine. The strangest part is that at one time, I had this working. It's almost as if the @csrf_exempt decorator isn't working.


Solution

  • I actually just resolved this. For anyone who's interested, the issue was the my urls.py was pointing to the wrong endpoint, so requests were being rejected. I altered this during some testing and forgot to change it back. Cost me quite a few hours. Devil's in the details!