From 0be62541ba227c8b4ea20bbfe922d4116372ba5d Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Sat, 2 Dec 2023 15:10:00 +0000 Subject: [PATCH] Handle chardet returning `None` as encoding --- devine/core/utilities.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devine/core/utilities.py b/devine/core/utilities.py index 146a841..e35a2b4 100644 --- a/devine/core/utilities.py +++ b/devine/core/utilities.py @@ -237,6 +237,8 @@ def try_ensure_utf8(data: bytes) -> bytes: try: # last ditch effort to detect encoding detection_result = chardet.detect(data) + if not detection_result["encoding"]: + return data return data.decode(detection_result["encoding"]).encode("utf8") except UnicodeDecodeError: return data