Force encoding to utf-8 on text file operations Fixes #332

This commit is contained in:
Marc-Andre Ferland 2022-10-17 22:35:51 -04:00
parent 03bd9a5731
commit 5b0b582039
2 changed files with 6 additions and 6 deletions

View File

@ -541,7 +541,7 @@ Negative Prompt: {req.negative_prompt}
Stable Diffusion Model: {req.use_stable_diffusion_model + '.ckpt'} Stable Diffusion Model: {req.use_stable_diffusion_model + '.ckpt'}
""" """
try: try:
with open(meta_out_path, 'w') as f: with open(meta_out_path, 'w', encoding='utf-8') as f:
f.write(metadata) f.write(metadata)
except: except:
print('could not save the file', traceback.format_exc()) print('could not save the file', traceback.format_exc())

View File

@ -187,13 +187,13 @@ async def setAppConfig(req : SetAppConfigRequest):
config_bat_path = os.path.join(CONFIG_DIR, 'config.bat') config_bat_path = os.path.join(CONFIG_DIR, 'config.bat')
config_sh_path = os.path.join(CONFIG_DIR, 'config.sh') config_sh_path = os.path.join(CONFIG_DIR, 'config.sh')
with open(config_json_path, 'w') as f: with open(config_json_path, 'w', encoding='utf-8') as f:
f.write(config_json_str) f.write(config_json_str)
with open(config_bat_path, 'w') as f: with open(config_bat_path, 'w', encoding='utf-8') as f:
f.write(config_bat_str) f.write(config_bat_str)
with open(config_sh_path, 'w') as f: with open(config_sh_path, 'w', encoding='utf-8') as f:
f.write(config_sh_str) f.write(config_sh_str)
return {'OK'} return {'OK'}
@ -206,7 +206,7 @@ def getConfig(default_val={}):
config_json_path = os.path.join(CONFIG_DIR, 'config.json') config_json_path = os.path.join(CONFIG_DIR, 'config.json')
if not os.path.exists(config_json_path): if not os.path.exists(config_json_path):
return default_val return default_val
with open(config_json_path, 'r') as f: with open(config_json_path, 'r', encoding='utf-8') as f:
return json.load(f) return json.load(f)
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
@ -216,7 +216,7 @@ def getConfig(default_val={}):
def setConfig(config): def setConfig(config):
try: try:
config_json_path = os.path.join(CONFIG_DIR, 'config.json') config_json_path = os.path.join(CONFIG_DIR, 'config.json')
with open(config_json_path, 'w') as f: with open(config_json_path, 'w', encoding='utf-8') as f:
return json.dump(config, f) return json.dump(config, f)
except: except:
print(str(e)) print(str(e))