DateTime strangeness when returning MySQLdb results thru xmlrpcserver
grahamd at dscpl.com.au
Sun Nov 25 02:20:53 CET 2001
Ken Guest <kwg at renre-europe.com> wrote in message news:<mailman.1006526702.7049.python-list at python.org>...
> OK, I've been writing an XML-RPC server in python to serve as an
> intermediate between a client app and a mysql database - this works fine
> for the most part in that I can open a database, execute sql and close
> the database at will.
> I'm using MySQLdb, xmlrpclib and xmlrpcserver to make all this work,
> the version of python that I'm using is 2.0.1 and my xmlrpclib is at
> version 0.9.9 with the last comment by Fredrik Lundh dated 2001-02-26.
> And it works just fine until the resultset being returned references a
> datetime column - and keep getting an Internal Error (ie status code =
> I tweaked xmlrpcserver.py to return the error type and value  and
> found that the reason is that xmlrpclib "cannot marshal <type
> 'DateTime'> objects".
> To be honest I'm not sure how the timestamps get converted to this type
> as MySQLdb returns them as strings and examining xmlrpclib.py hasn't
> shed as much light on the problem as I'd like.
If the DateTime package from egenix is installed, MySQLdb will use its
date and time types instead of returning strings. To cope with this when
using that particular XML-RPC server framework, you would need to extend
the marshallar class to handle that type. I can't remember if one can
instead override MySQLdb not to use the date and time types from egenix
As an alternative that already does what you want, you might look at:
This particular code already handles the possibility that MySQLdb might
return a DateTime class instance rather than a string, converting it back
to a string when it does.
More information about the Python-list