DatabaseError in Django with gunicorn and Apache Proxy

After I deployed my new shiny blog and postin the response to the first comment the server gave me a 500 (internal server) error.

Django mailed an errormessage to me (very nice):

invalid input syntax for type inet: "2a01"
LINE 1: ...de', E'', E'test', E'2011-02-18 23:41:56.785693', E'2a01', t...

My setup is as follows:

  • Django 1.3 (trunk atm)
  • executed by gunicorn
  • proxied by apache2
  • postgresql 8.4 database
  • client connected via IPv6.

The error occured in the comment application. I thought django would catch invalid values before executing the query. As I developed with postgresql 9, I suspected postgresql 8.4 could maybe not handle the ipv6 address? Just a wild guess. So I upgraded to postgresql 9 - but still the same problem.

Long story short: After rebuilding the deployment setup step-by-step on my development machine, it turned out, that gunicorn reported the wrong REMOTE_ADDR to django.

And why did it to that? Because the X-Forwarded-For header set by apache when proxying does not contain the port, just the pure IPv6 addresses (without the brackets embracing it to distinguish the colons in the address from the colon for the port). Gunicorn was not prepared to handle IPv6 adresses without brackets.

I filed a bug report and provided a possible patch, so I think the problem will be fixed in gunicorn soon.


Posted Feb. 19, 2011 / 18:18, tagged as: No comments yet.

New Blog (software)

I'm happy I finally deployed my new blog. It is a django application written by me. I think I'll open source the code some day, when I've integrated all the unique features I'm planning, which distinguish this blog from other software available.

One outcome of this development is already on github (and pypi of course): django-tweet-saved. This app sends a tweet after a model has been saved. Thanks to django (and the django contenttype framework) integrating this app with any model is very easy.

Now I'm going to blog more frequently than before (~ 3 Posts in 1,5 years), as I have some content that I really like to share.

Topics in this blog will be covered by my professional software development (currently Typo3 development) and interests as hobbyists/computer science student, covering django, python, web development in general, software engineering, server administration etc.

Accordingly my first blog post will cover django deployment with gunicorn, which I'll write down once I've given the rendering of sourcecode in blog posts the final touch.


Posted Feb. 17, 2011 / 22:09, tagged as: 105 comments