How to get info on Django HTTP 500 error

1.1k views Asked by At

I am running a Django 1.8 site on nginx/uWSGI.

On the ./manage.py runserver everything works as expected, but when I move it to production some views return an HTTP 500 error.

Looking into the uWSGI log I get something like:

** View: booking_accept_view 6zN6
[pid: 1959|app: 0|req: 7/7] xxx.xxx.xxx.xxx () {56 vars in 1339 bytes}
[Thu Jun 11 10:00:39 2015] GET /tidsbestilling/admin-accept/6zN6/ =>
generated 27 bytes in 28 msecs (HTTP/1.1 500)
6 headers in 226 bytes (2 switches on core 0)

So not much help here.

nginx access log:

xxx.xxx.xxx.xxx - - [11/Jun/2015:10:00:39 +0200] 
"GET /tidsbestilling/admin-accept/6zN6/ HTTP/1.1" 500 38 
"https://example.com/tidsbestilling/admin-details/6zN6/" 
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.10 
(KHTML, like Gecko) Version/8.0.7 Safari/600.7.10"

No entry in nginx error log.

I tried enclosing in a try-except block, but I get no information from that.

My view looks like this:

def booking_admin_accept_view(request, booking_uid):
    print("** View: booking_accept_view", booking_uid)

    user = request.user
    if not (user is not None and user.is_authenticated() and user.is_active):
        return HttpResponseRedirect(reverse('booking_admin_login_view'))

    try:
        booking = Booking.objects.get(uid=booking_uid)
        booking.status = 'accepted'
        booking.save()
        send_sms(booking)
        return HttpResponseRedirect(reverse('booking_admin_details_view', args=(booking_uid,)))
    except(Exception, e):
        logging.exception(e)

The booking.save() is executed, and if I do a ./manage.py shell I can do the send_sms(booking) and that works too, but the view doesn't get that far.

So my question is: how do I get more information on what's going wrong? Do I really have to run in DEBUG mode to get information?

1

There are 1 answers

0
aliasav On

Put the user = request.user also in a try-catch block.

Try logging the request to check headers.