fix: Fixed UnicodeDecodeError when reading json file in JsonDatasource

This commit is contained in:
LWR
2023-05-12 00:26:00 +08:00
parent ec54c693c7
commit 954f981fd0
2 changed files with 9 additions and 5 deletions
+6 -2
View File
@@ -213,10 +213,14 @@ class JsonDataSource(DataSource):
if self.__json_str is None: if self.__json_str is None:
try: try:
with open(self.__json_file, "r") as file: with open(self.__json_file, "r", encoding="utf-8") as file:
self.__json_str = file.read() self.__json_str = file.read()
except Exception: except FileNotFoundError:
raise DataSourceException("JSON 文件不存在, 请检查文件路径是否正确") raise DataSourceException("JSON 文件不存在, 请检查文件路径是否正确")
except UnicodeDecodeError:
raise DataSourceException("JSON 文件编码不正确, 请将其转换为 UTF-8 格式编码后重试")
except Exception as ex:
raise DataSourceException(f"读取 JSON 文件异常 {ex}")
try: try:
self.__config = json.loads(self.__json_str) self.__config = json.loads(self.__json_str)
+1 -1
View File
@@ -67,7 +67,7 @@ class LiveOff(BaseModel):
def default(cls): def default(cls):
""" """
获取功能全部开启的默认 LiveOff 实例 获取功能全部开启的默认 LiveOff 实例
默认配置:启用下播推送,推送内容模板为 "{uname} 直播结束了\n{time}{next}{danmu_count}{danmu_mvp}{box_profit}" 默认配置:启用下播推送,推送内容模板为 "{uname} 直播结束了"
""" """
return LiveOff(enabled=True, message=LiveOff.DEFAULT_MESSAGE) return LiveOff(enabled=True, message=LiveOff.DEFAULT_MESSAGE)