Python Forum

Full Version: Need help to read a gzip stream...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Following code errors, and I have tried every mechanism that is available on google search. Still could not get the stream to uncompress without errors. But the same file can be read in both Java and Scala.

orig_file_desc = GzipFile(mode='r', fileobj=(io.StringIO(fileResponse.text)))
csvReader = csv.reader((orig_file_desc))
print("two")
for csvReaderRow in csvReader:
print(', '.join(csvReaderRow))

And error for the above is "AttributeError: 'str' object has no attribute 'read'"

And various other errors for each other methods to get the job done. I used, zlib too.

Help is much much appreciated...
import gzip
with gzip.open('file.txt.gz', 'rb') as f:
    file_content = f.read()
heiner, why are you answering posts from 2017?
Because I am bored.
I hope this is allowed.
Sure it is.
Thanks