OSError: Not a gzipped file (b'\x80\x02')


While executing the Lesson 5- SGB-MNIST example I am getting an error on the sentence below.
with gzip.open(path/‘mnist.pkl.gz’, ‘rb’) as f:
((x_train, y_train), (x_valid, y_valid), _) = pickle.load(f, encoding=‘latin-1’)

Error thrown is : OSError: Not a gzipped file (b’\x80\x02’).

The file does exist in the folder but it seems that the gzip.open expects a magic header of b’\037\213’.

Please advise.

If you are using Mac OS X, the system automatically unzips the gz file and give you mnist.pkl after download. Did you somehow change the name back into mnist.pkl.gz?

Below is what I did in OS X and it worked fine for me:

with open(path/'mnist.pkl', 'rb') as f:
    ((x_train, y_train), (x_valid, y_valid), _) = pickle.load(f, encoding='latin-1')

Thank you George. Your feedback worked.

Thanks again.

Hello, I have been facing similar problem. The error output is `

OSError Traceback (most recent call last)
in ()
1 with gzip.open(path, ‘rb’) as f:
----> 2 ((x_train, y_train), (x_valid, y_valid), _) = pickle.load(f, encoding=‘latin-1’)

/anaconda3/lib/python3.6/gzip.py in peek(self, n)
294 import errno
295 raise OSError(errno.EBADF, “peek() on write-only GzipFile object”)
–> 296 return self._buffer.peek(n)
298 @property

/anaconda3/lib/python3.6/_compression.py in readinto(self, b)
66 def readinto(self, b):
67 with memoryview(b) as view, view.cast(“B”) as byte_view:
—> 68 data = self.read(len(byte_view))
69 byte_view[:len(data)] = data
70 return len(data)

/anaconda3/lib/python3.6/gzip.py in read(self, size)
461 # jump to the next member, if there is one.
462 self._init_read()
–> 463 if not self._read_gzip_header():
464 self._size = self._pos
465 return b""

/anaconda3/lib/python3.6/gzip.py in _read_gzip_header(self)
410 if magic != b’\037\213’:
–> 411 raise OSError(‘Not a gzipped file (%r)’ % magic)
413 (method, flag,

OSError: Not a gzipped file (b’<!’)`

please , who can help with this issue?


this is the path itself