Commit cf0a018f authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Fix charset encoding error while uploading csv

parent 3fb9c08c
......@@ -14,8 +14,13 @@ def build_tabulator_params(type, name, source):
# CSV: converts to string
if format == 'csv':
scheme = 'text'
encoding = helpers.detect_encoding(source)
source = source.decode(encoding)
# Try UTF-8 first, then fallback to detect_encoding,
# because detection sometimes fails and returns cp1252 instead of utf-8.
try:
source = source.decode("utf-8")
except UnicodeDecodeError:
encoding = helpers.detect_encoding(source)
source = source.decode(encoding)
# Else use custom BytesLoader
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment