I have a Python 2 pickle file that when I try to read it with Python 3 it shows the following error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
Here are some code sample in Python 2 and Python 3:
python_2_dump.py
# -*- coding: utf-8 -*-
# Python 2 version
import cPickle
test = {
'Á': 'A',
'á': 'a',
'Ã': 'A',
'ã': 'a',
'Â': 'A',
'â': 'a',
}
with open('test.pickle', 'w') as f:
cPickle.dump(test, f)
python_3_load.py
# Python 3 version
import pickle
with open('test.pickle', 'rb') as f:
print(pickle.load(f))
Is there any reason Python 3 doesn't detect the old protocol and convert it accordingly? If it was the other way around, i.e. Python 2 reading a Python 3 pickle data, it makes sense.