From a4b997a5f72b8977a15be1be9b99b2df26e9637b Mon Sep 17 00:00:00 2001 From: YJL626 <68042405+YJL626@users.noreply.github.com> Date: Sun, 27 Oct 2024 15:52:18 +0800 Subject: [PATCH] Catch the file format error and add a default value. --- chatgpt/globals.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chatgpt/globals.py b/chatgpt/globals.py index bad750f..bdd16fd 100644 --- a/chatgpt/globals.py +++ b/chatgpt/globals.py @@ -71,7 +71,10 @@ else: if os.path.exists(USER_AGENTS_FILE): with open(USER_AGENTS_FILE, "r", encoding="utf-8") as f: - user_agent_map = json.load(f) + try: + user_agent_map = json.load(file) + except json.JSONDecodeError: + user_agent_map = {} # token数量变化时,更新ua if len(user_agent_map.keys()) != len(token_list): new_tokens = list(set(token_list) - user_agent_map.keys())