From 0cfe47465d42831f6b1358a7e4c878cf70badafc Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Sun, 20 Mar 2022 02:27:55 +0100 Subject: [PATCH] Fix encoding for JSON files --- mvw-dl.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mvw-dl.py b/mvw-dl.py index 5e279d8..2bf2639 100644 --- a/mvw-dl.py +++ b/mvw-dl.py @@ -475,7 +475,7 @@ def state_file_none_or_valid_json( if os.path.exists(state_file_abs_path): if os.path.getsize(state_file_abs_path) > 0: - with open(state_file_abs_path, "r") as state_file: + with open(state_file_abs_path, "r", encoding="utf-8") as state_file: try: json.loads(state_file.read()) return True @@ -535,7 +535,7 @@ def log_successful_download( with lock: state_file_none_or_valid_json(state_file_abs_path) - with open(state_file_abs_path, "r+") as state_file: + with open(state_file_abs_path, "r+", encoding="utf-8") as state_file: try: json_state = json.load(state_file) except json.JSONDecodeError: @@ -544,12 +544,12 @@ def log_successful_download( json_state = [] log.debug(f"{shorthand_uuid} Writing log entry to '{state_file_abs_path}' ...") - with open(state_file_abs_path, "w") as state_file: + with open(state_file_abs_path, "w", encoding="utf-8") as state_file: json_state.append(state_entry) max_log_entries = config_obj.getint(section_name, "state_file_retention") if len(json_state) > max_log_entries: json_state = truncate_log(json_state, max_log_entries) - json.dump(json_state, state_file, indent=4, sort_keys=True) + json.dump(json_state, state_file, indent=4, sort_keys=True, ensure_ascii=False) def copy_url(