From 51fe97cf3cb766fddd9c837b9313a962ea3dd478 Mon Sep 17 00:00:00 2001 From: mccalluc Date: Mon, 6 Nov 2023 10:11:14 -0500 Subject: [PATCH 1/2] Parse EPW as Latin-1, so that non-ASCII characters do not error --- my_project/tab_select/app_select.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_project/tab_select/app_select.py b/my_project/tab_select/app_select.py index 3939d59..38a3675 100644 --- a/my_project/tab_select/app_select.py +++ b/my_project/tab_select/app_select.py @@ -163,7 +163,7 @@ def submitted_data( try: if "epw" in list_of_names[0]: # Assume that the user uploaded a CSV file - lines = io.StringIO(decoded.decode("utf-8")).read().split("\n") + lines = io.StringIO(decoded.decode("latin-1")).read().split("\n") df, location_info = create_df(lines, list_of_names[0]) return ( location_info, From a9a21880a7d2fbc532e1af17fe10125ea391e83e Mon Sep 17 00:00:00 2001 From: mccalluc Date: Fri, 10 Nov 2023 10:57:04 -0500 Subject: [PATCH 2/2] Try utf-8 first, fall back to latin-1 Also remove StringIO wrapper: seems unnecessary --- my_project/tab_select/app_select.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/my_project/tab_select/app_select.py b/my_project/tab_select/app_select.py index 38a3675..d530758 100644 --- a/my_project/tab_select/app_select.py +++ b/my_project/tab_select/app_select.py @@ -159,11 +159,15 @@ def submitted_data( ): content_type, content_string = list_of_contents[0].split(",") - decoded = base64.b64decode(content_string) + decoded_bytes = base64.b64decode(content_string) try: if "epw" in list_of_names[0]: # Assume that the user uploaded a CSV file - lines = io.StringIO(decoded.decode("latin-1")).read().split("\n") + try: + decoded_string = decoded_bytes.decode("utf-8") + except UnicodeDecodeError: + decoded_string = decoded_bytes.decode("latin-1") + lines = decoded_string.split("\n") df, location_info = create_df(lines, list_of_names[0]) return ( location_info,