[Twisted-web] Confused about XML-RPC Unicode behaviour (examples attached).

kgi iacovou at gmail.com
Wed Feb 7 12:41:41 CST 2007


Hi all.

I've got a bunch of Twisted XML-RPC servers that serve up a wide range of data 
types include dates. Up until now I've had some hacky code to protect against 
bad data types being returned to the serialization layer (Nones, unicodes, 
etc). However, this code turns out to be difficult to maintain, as well as 
being a modest performance hit.

I thought I see if I couldn't clean up some of the code to make it simpler and 
less hacky, and I found something rather odd: a Twisted XML-RPC server 
seemingly can't return a xmlrpc.DateTime object it has only just received 
from the deserialization layer.

I've attached a test client, using Twisted, and two test servers, one using 
Twisted, one using the standard library's SimpleXMLRPCServer.

The standard library version succeeds in returning the received 
xmlrpclib.DateTime unmolested; the Twisted version complains about the 
message containing unicode:

     File "/usr/lib/python2.4/site-packages/twisted/internet/abstract.py",line 
173, in write
            raise TypeError("Data must not be unicode")
        exceptions.TypeError: Data must not be unicode

This seems wrong: surely, at the very least, the serialization and 
deserialization should allow a round-trip unmodified? Put a slightly 
different way: I don't have a fundamental problem with the restriction that 
return types not include unicode, but surely in that case, the same system 
that enforces this should see to it that I don't receive such a type in the 
first place (given that the original data type I created in the client was a 
xmlrpclib.DateTime, which is explicitly designed for serialising over 
XML-RPC!).

Are there technical/historical/political reasons for this of which I know 
nothing?

Regards,

Ricky

-------------- next part --------------
A non-text attachment was scrubbed...
Name: simpledateserver.py
Type: application/x-python
Size: 599 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20070207/bf08d42f/simpledateserver.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dateclient.py
Type: application/x-python
Size: 495 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20070207/bf08d42f/dateclient.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dateserver.py
Type: application/x-python
Size: 763 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20070207/bf08d42f/dateserver.bin


More information about the Twisted-web mailing list