zlib, gzip and HTTP compression.

Robin Munn rmunn at pobox.com
Fri Jan 11 16:53:25 EST 2002


On 11 Jan 2002 11:38:29 -0800, Alan Kennedy <alanmk at hotmail.com> wrote:
>jj <jj at void.si> wrote in message news:<svct3uck4rce72mdl7drndt5v2a3965k45 at 4ax.com>...
>> dont use zlib, 
>> http requires data in gzip format, zlip.compress returns quite
>> different structure.
>> so import gzip ...
>
>Thanks JJ.
>
>OK, I understand the problem better now. I read RFC 1952, which
>explains the structure of gzip files. And looking at
>python/Lib/gzip.py, it appears to construct exactly the structure
>required.
>
>So I reworked my code to use gzip, and I'm almost there. The first
>~200 bytes of the HTML file now appear exactly as they should, but
>then it corrupts after that. Obviously the mechanism for communicating
>from the server to the client that I am sending gzipped data is
>working, but it looks like I'm sending gzipped data that is slightly
>corrupt, or I'm telling the client the wrong length, or some such.
>Close, but no cigar!
>
>There is obviously some small detail that I am missing, such as
>character translation during the print statement(?), one extra byte
>need somewhere, etc?
>
>Any hints anyone?
>
>The new code is presented below.
>
>TIA,
>
>Alan.
[snip code]

I have no idea if this might be causing your problem, but print adds a
newline after whatever it prints. What happens if you use
sys.stdout.write() instead?

-- 
Robin Munn
rmunn at pobox.com



More information about the Python-list mailing list