Expat incompatibility problem - Apache and Python
I got a machine (actually an EC2 instance using Fedora 8 i386 image) yesterday with Apache 2.2, Python 2.5 and mod_wsgi compiled and installed on it. I had to get my Django Application setup on that. This generally is a task that should not take more than 10 minutes, including checkout from SVN and setting up appropriate properties in the wsgi configuration file but unfortunately I hit the expat incompatibility issue between Apache and Python and spent half of my day fixing it, which I found later was a common enough problem that Django Book has devoted a paragraph on it.
Here’s what happened to me. Once I configured my Django Application, I could hit the home page of my application (which was nothing but some HTML and images), but as soon as I clicked a page linked off the home page, I got a blank screen. I checked my apache logs (error_log) and saw that it had the following error:
[Tue Apr 22 09:58:47 2008] [notice] child pid 2013 exit signal Aborted (6)
httpd: Objects/stringobject.c:107: PyString_FromString: Assertion `str != ((void *)0)' failed.
I googled a bit for this error, but couldn’t pin down the exact problem that was causing the above. Most of the sites that mentioned crashing of Apache pointed to the problem with the incompatibility of expat library. But they all talked about segmentation fault being thrown. With nothing else in hand, I decided to verify if expat was really the issue.
I checked the version of expat used by Apache and Python (instructions here) and they indeed were different. Apache was using 1.95.2, whereas Python was using 2.0.1. Before actually upgrading, I wanted to be sure that expat was an issue, so I wrote up a simple Django view that returned a single word in the HttpResponse. I added a line on top to import the expat library (import pyexpat). When I hit the page from the browser, I got a blank screen and the same error in the log files. Then I removed the import statement and I got the right response being rendered. This confirmed that pyexpat (or expat) was the cause of the problem.
I downloaded expat version 2.0.1 from SourceForge and build it on the system. Then I compiled apache again with –with-expat option specifying the directory where I had installed expat (/usr/local/expat). When I hit the page that was blank, it worked this time!!!!
While the problem is resolved, I am still confused why I didn’t see a segmentation fault.


Leave a Reply