1

I have a really strange Http500 error when loading dynamically generated images. And for some reason it only happens sometimes. The apache error log doesn't show any errors. The django development server used to serve them fine in development.

Example from the logs:

174.255.117.79 - - [04/Feb/2013:12:00:46 -0600] "GET /images/gender/ HTTP/1.1" 500 531 "http://okstereotype.me/results/" "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; XT862 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
174.255.117.79 - - [04/Feb/2013:12:00:46 -0600] "GET /images/bodytype/ HTTP/1.1" 500 531 "http://okstereotype.me/results/" "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; XT862 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
174.255.117.79 - - [04/Feb/2013:12:00:46 -0600] "GET /images/religion/ HTTP/1.1" 200 30722 "http://okstereotype.me/results/" "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; XT862 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
174.255.117.79 - - [04/Feb/2013:12:00:46 -0600] "GET /images/smoking/ HTTP/1.1" 200 58577 "http://okstereotype.me/results/" "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; XT862 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
174.255.117.79 - - [04/Feb/2013:12:00:47 -0600] "GET /images/ethnicities/ HTTP/1.1" 500 531 "http://okstereotype.me/results/" "Mozilla/5.0 (Linux; U; Android 4.0.4; en-us; XT862 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
~

And sometimes they load:

192.168.1.4 - - [04/Feb/2013:12:11:20 -0600] "GET /images/gender/ HTTP/1.1" 500 531 "http://okstereotype.me/results/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0"
192.168.1.4 - - [04/Feb/2013:12:11:20 -0600] "GET /images/religion/ HTTP/1.1" 200 41967 "http://okstereotype.me/results/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0"
192.168.1.4 - - [04/Feb/2013:12:11:20 -0600] "GET /images/ethnicities/ HTTP/1.1" 200 44148 "http://okstereotype.me/results/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0"
192.168.1.4 - - [04/Feb/2013:12:11:20 -0600] "GET /images/bodytype/ HTTP/1.1" 200 44471 "http://okstereotype.me/results/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0"
192.168.1.4 - - [04/Feb/2013:12:11:20 -0600] "GET /images/smoking/ HTTP/1.1" 200 59910 "http://okstereotype.me/results/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0"

The images are generated with a view:

(r'^images/(\w+)/$', mysite.views.show_pic)

And the view uses the PIL library to draw and save the image like so:

response = HttpResponse(mimetype="image/png")
img.save(response, "PNG")

All my static css is served correctly though. Any ideas?

2
  • Django should send you an email when an internal error occurs -- these contain a traceback which identifies the problem.
    – mgorven
    Feb 4, 2013 at 18:32
  • I used the logging hack from this question because I'm too lazy to set up mail. Basically it was a problem with object persistence when a user clicks back and then forward instead of going through forms one by one. Thanks a lot mgorven.
    – lqdc
    Feb 4, 2013 at 19:20

1 Answer 1

1

A good way to analyze the error would be making a copy of settings.py calling it "settings_test.py" for example. Then, set this copy to DEBUG=True and from a shell run - you can use some other port different than 80 or 443:

python manage.py runserver 0.0.0.0:5678 --settings relative.path.to.settings_test

or:

python django-admin.py runserver 0.0.0.0:5678 --settings relative.path.to.settings_test

Then, test it through this port (for instance: www.mydomain.com:5678/) and you will see a traceback if something happens. Even if it is a secondary GET/POST method that doesn't interfere with the mainpage's loading, you should see a traceback in the Shell like this.

Use Ctrl+C to interrupt the execution of runserver when you are done.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .