views:

49

answers:

1

I'm developing an application that uses webservices in python, both sides (server and client) are developed in Python and uses SOAPpy for the webservices, but, you know, the xml is too verbose, I want to compress it, but as far as I have searched in google I can't find something helpful.

+1  A: 

You can add HTTP headers to SOAPpy call as shown here (this example sends cookies, but you can generalize it to add different headers) -- to request compression, add header Accept-Encoding: gzip. The web server (not the application server, like your "SOAPpy server" in Python, but the actual HTTP server it runs on top on, e.g. Apache) should provide the compression and have in the response a header Content-Encoding: gzip to confirm that (if that doesn't work properly, you'll have to subclass the transport class and insert compression there yourself -- I have no SOAPpy installation at hand to check).

The missing bit is, how to trick your SOAPpy.SOAPProxy into decompression of the payload before further processing -- and the right approach is once again to subclass HTTPTransport, just as for the add-header part; in the URL above, look at the line data = response.read() and consider checking the headers (to confirm that the content encoding is gzip as required) and decompressing as needed.

To deal with gzip compression and decompression, of course, you can use the zlib module of Python's standard library (not the gzip module, which adds to zlib the header metadata processing to make and read .gz files -- you're not dealing with .gz files but with streams compressed with the gzip algorithm, and that's zlib's job).

Alex Martelli
Thank you, really helpful. I had already saw the recipe, but I didn't really understood it, not it looks a bit clearer. Thanks again.
markuz