Opened 10 years ago

Closed 8 years ago

#2446 enhancement closed fixed (fixed)

Python 2.4 has poor round-trip behaviour for xmlrpclib.DateTime; Twisted should work around.

Reported by: kgi Owned by:
Priority: normal Milestone:
Component: web Keywords: python2.4, xmlrpc, unicode
Cc: Branch: branches/xmlrpclib-datetime-hack-2446
branch-diff, diff-cov, branch-cov, buildbot
Author: exarkun


Python 2.4 has a quirky that means that re-serializing an un-serialized xmlrpclib.DateTime object results in it being stringified as Unicode, which causes Twisted's XML-RPC server to complain. Python 2.5 does not exhibit this behaviour. As a workaround, the file from Python 2.4 can be replaced with the same file from Python 2.5 and recompiled.

This was discussed on the twisted-web mailing list on 7 Feb 2007 with the subject, "Confused about XML-RPC Unicode behaviour". JP suggested that Twisted can probably work around the bug.

The email contained some example code. This is reproduced below for convenience.

Example server that complains:

# Run with 'twistd -noy'
from twisted.web         import xmlrpc
from twisted.web         import server
from twisted.application import strports
from twisted.application import service

class XMLRPCDateServer ( xmlrpc.XMLRPC ):
    def xmlrpc_echoDate ( self, the_date ):
        print "Received date: ", repr ( the_date ), the_date.__class__
        return the_date

resource    = XMLRPCDateServer()
application = service.Application ( "XMLRPCDateServer" )
site        = server.Site ( resource )
service     = strports.service ( "tcp:8111", site )
service.setServiceParent ( application )

Example client:

# Run with 'python'
import xmlrpclib
from twisted.internet import reactor
from twisted.web      import xmlrpc

def doIt():
    proxy = xmlrpc.Proxy ( 'http://localhost:8111' )
    the_date = xmlrpclib.DateTime()
    print "Sending Date: ", the_date

    def _cb ( r ):
        print "Received reply: ", r

    def _eb ( f ):
        print "Received error: ", f

    d = proxy.callRemote ( "echoDate", the_date )
    d.addCallbacks ( _cb, _eb )


The error received on Python 2.4 is:

2007/02/09 15:02 +0300 [HTTPChannel,0,] Received date:  <DateTime u'20070209T14:02:25' at -4872b754> xmlrpclib.DateTime
2007/02/09 15:02 +0300 [HTTPChannel,0,] Unhandled error in Deferred:
2007/02/09 15:02 +0300 [HTTPChannel,0,] Unhandled Error
        Traceback (most recent call last):
          File "/usr/lib/python2.4/site-packages/twisted/web/", line 167, in render
            body = resrc.render(self)
          File "/usr/lib/python2.4/site-packages/twisted/web/", line 118, in render
            defer.maybeDeferred(function, *args).addErrback(
          File "/usr/lib/python2.4/site-packages/twisted/internet/", line 191, in addCallback
          File "/usr/lib/python2.4/site-packages/twisted/internet/", line 182, in addCallbacks
        --- <exception caught here> ---
          File "/usr/lib/python2.4/site-packages/twisted/internet/", line 317, in _runCallbacks
            self.result = callback(self.result, *args, **kw)
          File "/usr/lib/python2.4/site-packages/twisted/web/", line 136, in _cbRender
          File "/usr/lib/python2.4/site-packages/twisted/web/", line 724, in write
          File "/usr/lib/python2.4/site-packages/twisted/internet/", line 173, in write
            raise TypeError("Data must not be unicode")
        exceptions.TypeError: Data must not be unicode

Change History (9)

comment:1 Changed 10 years ago by kgi

Component: coreweb
Owner: changed from Glyph to jknight

Realised that bug is better assigned to 'web' than 'core'.

comment:2 Changed 8 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/xmlrpclib-datetime-hack-2446

(In [26014]) Branching to 'xmlrpclib-datetime-hack-2446'

comment:3 Changed 8 years ago by Jean-Paul Calderone

Keywords: review added
Owner: jknight deleted

comment:4 Changed 8 years ago by Glyph

Owner: set to Jean-Paul Calderone

The test seems to hang, rather than fail, when the fix is removed, although a traceback is logged. Can you fix that?

comment:5 Changed 8 years ago by Glyph

Keywords: review removed

"Interrupted System Call", said trac, and only applied some of my changes. Nice.

comment:6 Changed 8 years ago by Jean-Paul Calderone

Keywords: review added
Owner: Jean-Paul Calderone deleted

trac is super great!

I added some more error handling to the XML-RPC server in r26032, and another new test for that. Response failures should happen fast now.

comment:7 Changed 8 years ago by Michael Hudson-Doyle

Keywords: review removed
Owner: set to Jean-Paul Calderone

Looks fine. Please merge.

comment:8 Changed 8 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [26099]) Merge xmlrpclib-datetime-hack-2446

Author: exarkun Reviewer: mwhudson Fixes: #2446

Add error handling to the fault serialization code in twisted.web.xmlrpc.XMLRPC so that responses are not left hanging indefinitely if there is an error serializing an error report. Also insert a monkey patch for xmlrpclib.DateTime deserialization so that these objects will correctly round-trip over XML-RPC on Python 2.3 and Python 2.4.

comment:9 Changed 6 years ago by <automation>

Owner: Jean-Paul Calderone deleted
Note: See TracTickets for help on using tickets.