mirror of
https://github.com/harry0703/MoneyPrinterTurbo.git
synced 2026-02-21 16:37:21 +08:00
Add exception handling for reading the configuration file and optimize the loading method
This commit is contained in:
parent
0d3b7b7c5c
commit
5933a47620
@ -15,8 +15,14 @@ if not os.path.isfile(config_file):
|
||||
|
||||
logger.info(f"load config from file: {config_file}")
|
||||
|
||||
with open(config_file, mode="rb") as fp:
|
||||
_cfg = tomli.load(fp)
|
||||
try:
|
||||
with open(config_file, mode="rb") as fp:
|
||||
_cfg = tomli.load(fp)
|
||||
except Exception as e:
|
||||
logger.warning(f"load config failed: {str(e)}, try to load as utf-8-sig")
|
||||
with open(config_file, mode="r", encoding='utf-8-sig') as fp:
|
||||
_cfg_content = fp.read()
|
||||
_cfg = tomli.loads(_cfg_content)
|
||||
|
||||
app = _cfg.get("app", {})
|
||||
whisper = _cfg.get("whisper", {})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user