This is the story of how I learned that it is a good idea to plan the deployment of your web projects ahead of time, and then match up your development environment with your chosen deployment environment as much as possible.

When developing this blog, I decided to use Python 2.5 for development because I wanted to use Sqlite which comes with Python 2.5. I liked the idea of being able to nuke the database by deleting a file.

When I went to deploy, I did so on a Linux box that was running mod_python hooked up to version 2.4 of Python. Rather than trying to rebuilt mod_python and whatnot, I decided to just back port my code.

It turned out to be non-trivial. And, problems are a lot harder to diagnose on a remote server.

The main problem turned out to be my XMLRPC code. It would appear that xmlrpclib got a big upgrade in Python 2.5. Which is good, unless you are back porting...

The first problem is that they changed SimpleXMLRPCDispatcher to take constructor arguments in 2.5 to deal with string encoding issues. That was pretty easy to find and fix.

# In Python 2.4 
dispatcher = SimpleXMLRPCDispatcher()

# In Python 2.5 
dispatcher = SimpleXMLRPCDispatcher(False,'UTF-8')

Next, came the hard part. I was getting an obscure error about an argument requiring a float. Over XMLRPC you only get the final error message and not a complete stack trace. I eventually tracked this down to xmlrpclib.DataTime. After digging through the Python source I figured out that the constructor for xmlrpclib.DataTime was extended in Python 2.5 to allow initializing with a Python datetime.datetime object, such as the ones Django returns. It seemed pretty logical that xmlrpclib.DataTime would support that, so it took me a while to figure out that it didn't support it in Python 2.4.

Anyway, for anyone still interested, here's the fix:

# In Python 2.4 (Note that I stole the strftime format string right from 
# Python 2.5's xmlrpclib source)
datetime = xmlrpclib.DateTime( post.date.strftime("%Y%m%dT%H:%M:%S") )

# In Python 2.5 
datetime = xmlrpclib.DateTime( post.date )
blog comments powered by Disqus
Disclaimer: The above statements and opinions are my own and do not represent those of my employer.