Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 8, 2011 02:05:39

C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Curious 500 errors


Hello, I am new to Django and working on integrating it with
MailChimp. I am implementing call back handlers for their Web Hooks.
This should be just views.

Anyway, I am testing running the dev server and seeing that the views
are called just fine for GET requests, but for POST requests, all I
see is this:

"POST /newsletters/callback HTTP/1.1" 500 63243

Even though I am printing output in the view code which should be
logging. Any ideas why this should be resulting in such an error on
the dev server? Because it is not printing anything out for POSTs it
must be somehow circumventing the view code. Am I missing something.

Here is my handler code:

def handle_mailchimp_callback(request):
response = http.HttpResponse()
response.status_code = 200
if request.POST:
print "POSTING"
else:
print "GETTTING"
return response

Here is the server console output for a GET request:

"GET /newsletters/callback HTTP/1.1" 301 0
GETTTING
"GET /newsletters/callback/ HTTP/1.1" 200 0


Thanks alot.

C.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 9, 2011 15:25:33

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Curious 500 errors


On Fri, Jan 7, 2011 at 7:57 PM, Conor <mcgann.co...@gmail.com> wrote:

> Hello, I am new to Django and working on integrating it with
> MailChimp. I am implementing call back handlers for their Web Hooks.
> This should be just views.
>
> Anyway, I am testing running the dev server and seeing that the views
> are called just fine for GET requests, but for POST requests, all I
> see is this:
>
> "POST /newsletters/callback HTTP/1.1" 500 63243
>
> Even though I am printing output in the view code which should be
> logging. Any ideas why this should be resulting in such an error on
> the dev server? Because it is not printing anything out for POSTs it
> must be somehow circumventing the view code. Am I missing something.
>
> Here is my handler code:
>
> def handle_mailchimp_callback(request):
> response = http.HttpResponse()
> response.status_code = 200
> if request.POST:
> print "POSTING"
> else:
> print "GETTTING"
> return response
>
> Here is the server console output for a GET request:
>
> "GET /newsletters/callback HTTP/1.1" 301 0
> GETTTING
> "GET /newsletters/callback/ HTTP/1.1" 200 0
>

That GET output is showing that the callback URL without a slash at the end
is getting redirected to a version with the slash at the end.

For POST, with DEBUG=True, Django attempts to notify you (as far back as
release 1.0) of the potential problem of loss of post data during this
redirect via this code:http://code.djangoproject.com/browser/django/tags/releases/1.0/django/middleware/common.py#L60I don't know MailChimp, but you should either configure it to request
callback URLs that include trailing slashes, or configure your URLs for
these callbacks so that they do not require the trailing slash.

Karen
--http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 10, 2011 11:28:22

Justin M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Curious 500 errors


Hi Conor,

You might be running into a CSRF protection error. Django expects a
CSRF token for all POST requests and the MailChimp webhooks aren't
sending one. You will need to decorate your views as @csrf_exempt in
order for them to work. Just make sure that you do some extra
validation on your part for security issues.

Example:
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def handle_mailchimp_callback(request):
...

Here is a link to the Django CSRF documentation:http://docs.djangoproject.com/en/dev/ref/contrib/csrf/?from=olddocs#exceptions-Justin

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support