From 2bc3da015560054fc391ecd2a5e5d210f827e6d6 Mon Sep 17 00:00:00 2001 From: kingbri Date: Wed, 29 Nov 2023 22:04:29 -0500 Subject: [PATCH] YAML: Force all files to open with utf8 The default encoding method when opening files on Windows is cp1252 which doesn't support all unicode and can cause issues. Signed-off-by: kingbri --- auth.py | 4 ++-- main.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/auth.py b/auth.py index 62ccd92..df0fbc5 100644 --- a/auth.py +++ b/auth.py @@ -31,7 +31,7 @@ auth_keys: Optional[AuthKeys] = None def load_auth_keys(): global auth_keys try: - with open("api_tokens.yml", "r") as auth_file: + with open("api_tokens.yml", "r", encoding = 'utf8') as auth_file: auth_keys_dict = yaml.safe_load(auth_file) auth_keys = AuthKeys( api_key = auth_keys_dict["api_key"], @@ -44,7 +44,7 @@ def load_auth_keys(): ) auth_keys = new_auth_keys - with open("api_tokens.yml", "w") as auth_file: + with open("api_tokens.yml", "w", encoding = "utf8") as auth_file: yaml.safe_dump(vars(auth_keys), auth_file, default_flow_style=False) print( diff --git a/main.py b/main.py index 1948373..e5d7d26 100644 --- a/main.py +++ b/main.py @@ -229,7 +229,7 @@ if __name__ == "__main__": # Load from YAML config. Possibly add a config -> kwargs conversion function try: - with open('config.yml', 'r') as config_file: + with open('config.yml', 'r', encoding = "utf8") as config_file: config = yaml.safe_load(config_file) or {} except Exception as e: print(