I Have two server running one is running on python2.7 and another on python3.8.
for both the servers we have the common Django-cache server.
python2.7 server is setting up cache in the Django-cache and python3.8 trying to read this throwing an error saying
File “/usr/local/bin/python-3.8.0/lib/python3.8/site-packages/django_redis/serializers/pickle.py”, line > 35, in loads
return pickle.loads(value)
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 1: ordinal not in range(128)
i already read the below post with the same question link
my goal here is to able to read and from both versions of python to the common django-cache.
2
Answers
The solution which worked for me is we implemented a custom serializer and adder that in the redis_cache config.
if you use the encoding method as
'bytes'
. you can get bytes else you will get a string.and the below-mentioned line in the
cache config
inside thesettings.py
.'SERIALIZER':'file.location.CustomPickleSerializer'
in.Default
str
encoding inpython 2.7
isASCII
while the default for 3.x isutf-8
so you need to consider this.If you look closely it’s not Redis issue, it’s encoding issue, hence the error message:
To solve this problem you have to set the default encoding to
utf-8
in your python 2.7 program.There are more details about the python encoding conversion issue here: How to fix UnicodeDecoderError