From 571b0ad205ab8d71df7ec489a1fab7b17e1668da Mon Sep 17 00:00:00 2001 From: Jian Dai Date: Fri, 30 Nov 2018 00:30:52 +0800 Subject: [PATCH] fix bytes_to_str bug (#747) When we were using celery , and using `pickle` format to transfer a bytes variable like a file content, for example a picture file, then we will get an exception here. ```UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte``` So add `errors='replace'` to avoid the encoding error here. --- kombu/utils/encoding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kombu/utils/encoding.py b/kombu/utils/encoding.py index 93788bde..551cf5f3 100644 --- a/kombu/utils/encoding.py +++ b/kombu/utils/encoding.py @@ -53,7 +53,7 @@ if PY3: # pragma: no cover def bytes_to_str(s): """Convert bytes to str.""" if isinstance(s, bytes): - return s.decode() + return s.decode(errors='replace') return s def from_utf8(s, *args, **kwargs):