1

I've tried to read and load pickle files in Python3.

import pickle as pickle
pickleFileName = 'data/fingerDataSet' + '.pickle'
pickleFile = open(pickleFileName, 'rb')
data = pickle.load(pickleFile)
pickleFile.close()

but in line data = pickle.load(pickleFile) I'm getting strange error UnicodeDecodeError: 'ascii' codec can't decode byte 0xc0 in position 5: ordinal not in range(128)

asked Jan 10, 2020 at 18:44
5
  • How was the file written and what did it contain? Commented Jan 10, 2020 at 18:54
  • In unicode, 0xc0 is the letter À. So the problem should be in the file Commented Jan 10, 2020 at 18:55
  • I meant more along the lines of what python object was pickled and written to the file? Commented Jan 10, 2020 at 18:56
  • I've found some hosting and uploaded file there so uploadfiles.io/90rlmu5d It should be an image of a finger, this works in Python2 so the file is ok. Commented Jan 10, 2020 at 19:04
  • Unpickling from an untrusted source is a bad idea. Additionally, unpickling data with python 3 that was pickled in python 2 has it's own issues. stackoverflow.com/questions/28218466/… Commented Jan 10, 2020 at 19:16

1 Answer 1

1

Pickle is not intended to work across different Python versions. What is likely in this case is that the original data was in a Python 2 str, which contains bytes, and the Python3 version is trying to read it as text, performing an implicit decode.

What you should do there is to unpickle your data in a Python 2 environment, and save it in a way that is not dependente on the Python version (if it is an image, use the PIL library to write a PNG file, for example)

answered Jan 10, 2020 at 20:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.