I'm using the following code from here (with minor edits):
import _pickle as cPickle
def unpickle(file):
fo = open(file, 'rb')
dict = cPickle.load(fo)
fo.close()
return dict
unpickle('data_batch_1')
When I run the code, I get the following, provided that I'm using Python 3.5.2
:
Traceback (most recent call last):
File "open_batch.py", line 10, in <module>
unpickle('data_batch_1')
File "open_batch.py", line 5, in unpickle
dict = cPickle.load(fo)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 6: ordinal not in range(128)
How can I fix this issue?
Thanks.
Since it fails on the encoding of the characters
Try using latin
cPickle.load(file, encoding='latin1')
replace:
dict = cPickle.load(fo)
in unpickle function with:
dict = cPickle.load(fo, encoding='latin1')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With