From 945460fb35fe56b0a6df299952f77151dcecd069 Mon Sep 17 00:00:00 2001 From: Huiting Chen Date: Tue, 23 Dec 2025 12:49:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(http):=20=F0=9F=90=9B=20Fix=20RequestUt?= =?UTF-8?q?ils.get=5Fclient()=20AttributeError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The get_client() method was returning cls.client which doesn't exist, causing AttributeError: type object 'RequestUtils' has no attribute 'client' - 🔧 Change __client from class reference to None with type hint - ✨ Implement lazy initialization pattern for HTTPClient instance - 🐛 Fix incorrect attribute access (cls.client -> cls.__client) --- app/utils/http.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/utils/http.py b/app/utils/http.py index 1040017..273545f 100644 --- a/app/utils/http.py +++ b/app/utils/http.py @@ -338,7 +338,7 @@ class RequestUtils: 支持同步和异步请求 """ - __client = HTTPClient + __client: HTTPClient | None = None @classmethod def get_client(cls, *_, **__) -> HTTPClient: @@ -348,7 +348,9 @@ def get_client(cls, *_, **__) -> HTTPClient: :param url: 请求的 URL :return: HTTP 客户端 """ - return cls.client + if cls.__client is None: + cls.__client = HTTPClient() + return cls.__client @overload @classmethod From 753a8741838ea5c768889c43b12c21d15a037fa7 Mon Sep 17 00:00:00 2001 From: Huiting Chen Date: Tue, 23 Dec 2025 13:08:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(config):=20=F0=9F=90=9B=20Fix=20TypeErr?= =?UTF-8?q?or=20in=20=5F=5Fmkdir=20using=20Path=20as=20context=20manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Path objects do not support the context manager protocol. The 'with' statement was incorrectly used with PosixPath objects, causing TypeError on startup. - 🔧 Remove invalid 'with' statement for CONFIG_DIR and LOG_DIR - ✨ Directly use Path.exists() and Path.mkdir() methods --- app/core/config.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 24bd82b..8fb5b46 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -30,13 +30,11 @@ def __mkdir(self) -> None: """ 创建目录 """ - with self.CONFIG_DIR as dir_path: - if not dir_path.exists(): - dir_path.mkdir(parents=True, exist_ok=True) + if not self.CONFIG_DIR.exists(): + self.CONFIG_DIR.mkdir(parents=True, exist_ok=True) - with self.LOG_DIR as dir_path: - if not dir_path.exists(): - dir_path.mkdir(parents=True, exist_ok=True) + if not self.LOG_DIR.exists(): + self.LOG_DIR.mkdir(parents=True, exist_ok=True) def __load_mode(self) -> None: """