From 957d73a76ece5284c1920431bfccea7edf96a502 Mon Sep 17 00:00:00 2001 From: hlohaus <983577+hlohaus@users.noreply.github.com> Date: Fri, 5 Dec 2025 23:34:10 +0100 Subject: [PATCH] Add UTF-8 encoding to file writes in Backend_Api class --- g4f/gui/server/backend_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/g4f/gui/server/backend_api.py b/g4f/gui/server/backend_api.py index 2d509a06..a391349d 100644 --- a/g4f/gui/server/backend_api.py +++ b/g4f/gui/server/backend_api.py @@ -440,7 +440,7 @@ class Backend_Api(Api): os.remove(copyfile) continue if not is_media and result: - with open(os.path.join(bucket_dir, f"{filename}.md"), 'w') as f: + with open(os.path.join(bucket_dir, f"{filename}.md"), 'w', encoding="utf-8") as f: f.write(f"{result}\n") filenames.append(f"{filename}.md") if is_media: @@ -477,7 +477,7 @@ class Backend_Api(Api): except OSError: shutil.copyfile(copyfile, newfile) os.remove(copyfile) - with open(os.path.join(bucket_dir, "files.txt"), 'w') as f: + with open(os.path.join(bucket_dir, "files.txt"), 'w', encoding="utf-8") as f: for filename in filenames: f.write(f"{filename}\n") return {"bucket_id": bucket_id, "files": filenames, "media": media} @@ -572,7 +572,7 @@ class Backend_Api(Api): share_id = secure_filename(share_id) bucket_dir = get_bucket_dir(share_id) os.makedirs(bucket_dir, exist_ok=True) - with open(os.path.join(bucket_dir, "chat.json"), 'w') as f: + with open(os.path.join(bucket_dir, "chat.json"), 'w', encoding="utf-8") as f: json.dump(chat_data, f) self.chat_cache[share_id] = updated return {"share_id": share_id}