Deflate with urllib2...

Sam samslists at gmail.com
Tue Sep 16 20:58:31 EDT 2008


Gabriel, et al.

It's hard to find a web site that uses deflate these days.

Luckily, slashdot to the rescue.

I even wrote a test script.

If someone can tell me what's wrong that would be great.

Here's what I get when I run it:
Data is compressed using deflate.  Length is:   107160
Traceback (most recent call last):
  File "my_deflate_test.py", line 19, in <module>
    data = zlib.decompress(data)
zlib.error: Error -3 while decompressing data: incorrect header check

And here's my test script:

#!/usr/bin/env python

import urllib2
import zlib

opener = urllib2.build_opener()
opener.addheaders = [('Accept-encoding', 'deflate')]

stream = opener.open('http://www.slashdot.org')
data = stream.read()
encoded = stream.headers.get('Content-Encoding')

if encoded == 'deflate':
    print "Data is compressed using deflate.  Length is:  ",
str(len(data))
    data = zlib.decompress(data)
    print "After uncompressing, length is: ", str(len(data))
else:
    print "Data is not deflated."



On Sep 10, 12:50 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Tue, 09 Sep 2008 16:38:54 -0300, Sam <samsli... at gmail.com> escribió:
>
> > Un-deflating doesn't work.  I get "zlib.error: Error -3 while
> > decompressing data: incorrect header check"
>
> zlib.decompress should work - can you provide a site that usesdeflateto  
> test?





More information about the Python-list mailing list