From 5dd90e186935e9d765d172d3219f0b0a7577c104 Mon Sep 17 00:00:00 2001 From: YJL626 <68042405+YJL626@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:34:47 +0800 Subject: [PATCH 1/2] Fix the bug where appending content causes a file format error. --- chatgpt/authorization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt/authorization.py b/chatgpt/authorization.py index 99f6811..16cfcaf 100644 --- a/chatgpt/authorization.py +++ b/chatgpt/authorization.py @@ -62,7 +62,7 @@ def get_ua(req_token): "impersonate": random.choice(globals.impersonate_list), } globals.user_agent_map[req_token] = user_agent - with open(globals.USER_AGENTS_FILE, "a", encoding="utf-8") as f: + with open(globals.USER_AGENTS_FILE, "w", encoding="utf-8") as f: f.write(json.dumps({req_token: user_agent}, indent=4)) return user_agent else: From 87a8ebfb69fa25996073b437e0172c06696fac4a Mon Sep 17 00:00:00 2001 From: YJL626 <68042405+YJL626@users.noreply.github.com> Date: Sun, 27 Oct 2024 15:30:00 +0800 Subject: [PATCH 2/2] Update authorization.py --- chatgpt/authorization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt/authorization.py b/chatgpt/authorization.py index 16cfcaf..af6d616 100644 --- a/chatgpt/authorization.py +++ b/chatgpt/authorization.py @@ -63,7 +63,7 @@ def get_ua(req_token): } globals.user_agent_map[req_token] = user_agent with open(globals.USER_AGENTS_FILE, "w", encoding="utf-8") as f: - f.write(json.dumps({req_token: user_agent}, indent=4)) + f.write(json.dumps(globals.user_agent_map, indent=4)) return user_agent else: return user_agent