From dd6ed4f2e23e6624a8d8b5e0b810f01a91632f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20D=C3=B6hne?= Date: Sat, 5 Jun 2021 22:09:55 +0200 Subject: [PATCH] Use UTF-8 in case of encoding error --- stellarisdashboard/parsing/save_parser.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stellarisdashboard/parsing/save_parser.py b/stellarisdashboard/parsing/save_parser.py index dd83a43..c1e6445 100644 --- a/stellarisdashboard/parsing/save_parser.py +++ b/stellarisdashboard/parsing/save_parser.py @@ -383,8 +383,13 @@ def parse_save(self, filename): self.save_filename = filename logger.info(f"Parsing Save File {self.save_filename}...") with zipfile.ZipFile(self.save_filename) as save_zip: - # encoding guess based on EU4 wiki https://eu4.paradoxwikis.com/Save-game_editing#File_locations - gamestate = save_zip.read("gamestate").decode("cp1252") + gamestate = save_zip.read("gamestate") + try: + # default encoding guess based on EU4 wiki https://eu4.paradoxwikis.com/Save-game_editing#File_locations + gamestate = gamestate.decode("cp1252") + except UnicodeError: + # attempt UTF-8, ignoring any further errors + gamestate = gamestate.decode("utf-8", errors="ignore") self.parse_from_string(gamestate) return self.gamestate_dict