You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I realize that I am very late with the python3 migration, so I understand if this ticket is closed right away. However others running into the same issue can hopefully benefit from this report.
Using encoding='latin1' is required for unpickling NumPy arrays and instances of datetime, date and time pickled by Python 2.
However the default encoding for unpickling is US-ASCII, thus one cannot deserialize datetime, date and time objects as well as NumPy arrays if they have been serialized in Python 2. Many migrate from Python 2 to Python 3 using a path were both versions run in parallel for some time.
Allowing to configure the encoding used for pickle.load()/_PylibMC_pickle_loads would resolve the issue. I also added a workaround below.
Environment
pylibmc==1.6.1
memcached 1.6.6
python 2.7.18 and 3.6.11
importsysimportpylibmcfrompickleimportloadaspickle_loadfromioimportBytesIOfromdatetimeimportdatetimeclient=pylibmc.Client(["localhost:11211"], behaviors={"pickle_protocol": 2}, binary=True)
# this worksclient.get("testText")
client.get("testDict")
# this fails with: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 1: ordinal not in range(128)client.get("testDatetime")
Expected behaviour
The datetime object (as well as the others) is correctly retrieved from the cache
Actual Behaviour
The datetime object cannot be deserialized
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 1: ordinal not in range(128)
The text was updated successfully, but these errors were encountered:
LaughInJar
changed the title
NumPy arrays and instances of datetime, date and time pickled by Python 2 cannot be deserialized in Python 3
NumPy arrays and instances of datetime, date and time pickled in Python 2 cannot be deserialized in Python 3
Sep 16, 2020
I will leave this up as your workaround seems good (though a bit unorthodox to put class-level function definitions inside if blocks 😆). I realize we should probably be exposing all the constants such as PYLIBMC_FLAG_PICKLE on the _pylibmc module.
I realize that I am very late with the python3 migration, so I understand if this ticket is closed right away. However others running into the same issue can hopefully benefit from this report.
According to the docs for pickle inPython 3:
However the default encoding for unpickling is US-ASCII, thus one cannot deserialize datetime, date and time objects as well as NumPy arrays if they have been serialized in Python 2. Many migrate from Python 2 to Python 3 using a path were both versions run in parallel for some time.
Allowing to configure the encoding used for
pickle.load()
/_PylibMC_pickle_loads
would resolve the issue. I also added a workaround below.Environment
pylibmc==1.6.1
memcached 1.6.6
python 2.7.18 and 3.6.11
Steps to reproduce
In the Python 2 environment:
In the Python 3 environment:
Expected behaviour
The datetime object (as well as the others) is correctly retrieved from the cache
Actual Behaviour
The datetime object cannot be deserialized
Workaround
The text was updated successfully, but these errors were encountered: