zlib, gzip and HTTP compression.

Alan Kennedy alanmk at hotmail.com
Sat Jan 12 14:00:29 CET 2002


rmunn at pobox.com (Robin Munn) wrote in message 
> 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?

I tried that, but unfortunately to no avail.

When outputting the HTTP headers, they should be separated by CR-LF,
or "\r\n" in a python string, so print is definitely doing the right
thing there. When it comes to the HTTP body, I don't think print does
any translation, although things might get confused if it added at
CRLF after the HTTP body.

But to be sure to be sure, I changed

-------------------
print "Content-Encoding: gzip"
print "Content-Length: %d" % (len(zbuf))
print                    # end of headers
print zbuf               # and then the buffer
-------------------

to 

-------------------
sys.stdout.write("Content-Encoding: gzip\r\n")
sys.stdout.write("Content-Length: %d\r\n" % (len(zbuf)))
sys.stdout.write("\r\n") # end of headers
sys.stdout.write(zbuf)   # and then the buffer
-------------------

But got exactly the same results between the two.

It was definitely worth a try.

I'm going to get to the bottom of this!

optimistical-ly yrs :-)

Alan.



More information about the Python-list mailing list