mirror of
https://github.com/devine-dl/devine.git
synced 2025-04-30 01:59:44 +00:00
Handle chardet returning None
as encoding
This commit is contained in:
parent
c31ee338dc
commit
0be62541ba
@ -237,6 +237,8 @@ def try_ensure_utf8(data: bytes) -> bytes:
|
|||||||
try:
|
try:
|
||||||
# last ditch effort to detect encoding
|
# last ditch effort to detect encoding
|
||||||
detection_result = chardet.detect(data)
|
detection_result = chardet.detect(data)
|
||||||
|
if not detection_result["encoding"]:
|
||||||
|
return data
|
||||||
return data.decode(detection_result["encoding"]).encode("utf8")
|
return data.decode(detection_result["encoding"]).encode("utf8")
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
return data
|
return data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user