python3: unpickle tzinfo pickled with python2

Bug #1631989 reported by ricolai on 2016-10-10
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description


Yes, pickle is not guaranteed to be cross-compatible between python versions, but it's so close !!


Dump in python 2:

import pickle, pytz, datetime
with open("date.pickle", "wb") as fp:
    pickle.dump(pytz.timezone('Europe/Paris').localize(datetime.datetime(2016, 1, 1)), fp)


Load in python 3:

import pickle
with open("date.pickle", "rb") as fp:
    pickle.load(fp, encoding="bytes") # encoding="bytes" so that pickle can load old str
# fails with
# AttributeError: 'bytes' object has no attribute 'encode'
# because calls 'ascii(zone)' for something that is already in bytes


pytz.ascii should not .encode 'bytes', that's it !

Thanks !

Stuart Bishop (stub) on 2016-10-26
Changed in pytz:
status: New → Triaged
importance: Undecided → High
Stuart Bishop (stub) on 2017-10-30
Changed in pytz:
status: Triaged → Fix Committed
Stuart Bishop (stub) on 2017-10-30
Changed in pytz:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers