I am trying to extract a file from inside a .gz file (or unzip it? don't really know the right nomenclature here) using python 3.8 (tried 3.7 too) and the gzip library on Windows, but I am getting the following error:
gzip.BadGzipFile: Not a gzipped file (b'\r\n')
Here's the file, so the error is reproducible (it's a publicly available file):
https://www.dropbox.com/s/2cs9ik9nj2tfijh/15_07_U_2020-01-24.CAT.gz?dl=0
In order to extract it, I am using the code from this question. The code is:
import gzip
import shutil
with gzip.open('15_07_U_2020-01-24.CAT.gz', 'rb') as f_in:
with open('file.txt', 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
Also, using code from this other question, I can read and see the content of the file:
for data in gzip.GzipFile(file):
print(data)
Here, I get the same error after printing the whole file.
So, it seems that the symbols '\r\n' that are at the end of the file are causing the error. But how can I deal with this? Can I ignore this error, or remove the symbols somehow?
By the way, I can extract the file with WinRAR or 7z without troubles.