Python3.1: gzip encoding with UTF-8 fails

Johannes Bauer dfnsonfsduifb at gmx.de
Sun Dec 20 11:08:33 EST 2009


Hello group,

with this following program:

#!/usr/bin/python3
import gzip
x = gzip.open("testdatei", "wb")
x.write("ä")
x.close()

I get a broken .gzip file when decompressing:

$ cat testdatei |gunzip
ä
gzip: stdin: invalid compressed data--length error

As it only happens with UTF-8 characters, I suppose the gzip module
writes a length of 1 in the gzip file header (one character "ä"), but
then actually writes 2 characters (0xc3 0xa4).

Is there a solution?

Regards,
Johannes

-- 
"Aus starken Potentialen können starke Erdbeben resultieren; es können
aber auch kleine entstehen - und "du" wirst es nicht für möglich halten
(!), doch sieh': Es können dabei auch gar keine Erdbeben resultieren."
-- "Rüdiger Thomas" alias Thomas Schulz in dsa über seine "Vorhersagen"
<1a30da36-68a2-4977-9eed-154265b17d28 at q14g2000vbi.googlegroups.com>



More information about the Python-list mailing list