Trouble sending / receiving compressed data (using zlib) as HTTP POST to server (in django)

Piet van Oostrum piet at
Sat Oct 3 13:03:15 CEST 2009

>>>>> subeen <tamim.shahriar at> (s) wrote:

>s> Hi,
>s> I am trying to send compressed data to a server written in django. But
>s> it shows error while decompressing the data in the server. After some
>s> experiment I found that the server is not receiving the exact data I
>s> am sending.

>s> data = 'hello, this is a test message this is another message'
>s> data = zlib.compress(data)
>s> # now it looks like: x��H����Q(��,V�D����.�������T�p^~IFj.L.�.e
>s> # length is 45

Note: you can't just paste binary data in the message and expect
something sensible. Better use the result of 'print data'.

>s> in django (view) I receive it:
>s> data = request.POST['data']
>s> # now it looks like: x����Q(�,V�D���.����^~IFj.L.�.e
>s> # length is 34

>s> Can anybody help me understand the issue and how to get over?

How did you post the data? If you post binary data you should indicate
this with a proper mime type, like application/octet-stream. Otherwise
it might be interpreted as text which it isn't.
Piet van Oostrum <piet at>
PGP key: [8DAE142BE17999C4]

More information about the Python-list mailing list