Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pickle error in python3.0rc1 #48153

Closed
Georg mannequin opened this issue Sep 18, 2008 · 2 comments
Closed

pickle error in python3.0rc1 #48153

Georg mannequin opened this issue Sep 18, 2008 · 2 comments
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@Georg
Copy link
Mannequin

Georg mannequin commented Sep 18, 2008

BPO 3903
Nosy @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-09-18.21:04:49.726>
created_at = <Date 2008-09-18.20:58:34.177>
labels = ['extension-modules', 'type-bug', 'invalid']
title = 'pickle error in python3.0rc1'
updated_at = <Date 2008-09-18.21:04:49.713>
user = 'https://bugs.python.org/Georg'

bugs.python.org fields:

activity = <Date 2008-09-18.21:04:49.713>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2008-09-18.21:04:49.726>
closer = 'benjamin.peterson'
components = ['Extension Modules']
creation = <Date 2008-09-18.20:58:34.177>
creator = 'Georg'
dependencies = []
files = []
hgrepos = []
issue_num = 3903
keywords = []
message_count = 2.0
messages = ['73399', '73400']
nosy_count = 2.0
nosy_names = ['benjamin.peterson', 'Georg']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue3903'
versions = ['Python 3.0']

@Georg
Copy link
Mannequin Author

Georg mannequin commented Sep 18, 2008

Hi all,
I compiled Python3.0rc1 with the usual ./configure make make test make
install on my Athlon XP 1800 (32 bit), using Debian Etch as OS, the
following works on Python2.4 (default in Debian Etch), but not with
Python3.0rc1:

>>> import pickle
>>> d = {'ID':345, 'AD':'Hallo'}
>>> f = open('test.hhh', 'wb')
>>> pickle.dump(d,f,2)
>>> f.close()
>>> f = open('test.hhh', 'r')
>>> pickle.load(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.0/pickle.py", line 1325, in load
    return Unpickler(file, encoding=encoding, errors=errors).load()
  File "/usr/local/lib/python3.0/io.py", line 1728, in read
    eof = not self._read_chunk()
  File "/usr/local/lib/python3.0/io.py", line 1557, in _read_chunk
    self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
  File "/usr/local/lib/python3.0/io.py", line 1294, in decode
    output = self.decoder.decode(input, final=final)
  File "/usr/local/lib/python3.0/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0:
unexpected code byte
>>>

the same if you specifiy protocol number 3, it works also in
Python3.0rc1 if you specifiy 'rb' instead of 'r' as file opening method,
but according to the Python library reference it should work also with
'r'. How should one know with which protocol the object was pickled?

Thanks very much,

Georg

@Georg Georg mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Sep 18, 2008
@benjaminp
Copy link
Contributor

Pickled files should *always* be used in binary mode.

The 3.0 pickle documentation states this:

"Be sure to always open pickle files created with protocols >= 1 in
binary mode. For the old ASCII-based pickle protocol 0 you can use
either text mode or binary mode as long as you stay consistent.

A pickle file written with protocol 0 in binary mode will contain lone
linefeeds as line terminators and therefore will look “funny” when
viewed in Notepad or other editors which do not support this format."

[1] http://docs.python.org/dev/3.0/library/pickle.html#usage

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant