mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
fix(zhenxun): 修复 HTTP 客户端初始化逻辑错误
- 将 httpx.AsyncClient 实例化逻辑封装到 get_async_client 函数中 - 统一全局客户端和测试环境客户端的创建方式 - 提高代码复用性和可维护性
This commit is contained in:
parent
3deffcb46c
commit
c7793d1de7
@ -61,7 +61,7 @@ async def _():
|
|||||||
"将默认使用新版 'proxy' 参数语法。"
|
"将默认使用新版 'proxy' 参数语法。"
|
||||||
)
|
)
|
||||||
|
|
||||||
_client = httpx.AsyncClient(
|
_client = get_async_client(
|
||||||
headers=get_user_agent(),
|
headers=get_user_agent(),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
**client_kwargs,
|
**client_kwargs,
|
||||||
@ -90,7 +90,7 @@ def get_client() -> AsyncClient:
|
|||||||
raise RuntimeError("全局 httpx.AsyncClient 未初始化,请检查启动流程。")
|
raise RuntimeError("全局 httpx.AsyncClient 未初始化,请检查启动流程。")
|
||||||
# 在测试环境中创建临时客户端
|
# 在测试环境中创建临时客户端
|
||||||
logger.warning("在测试环境中创建临时HTTP客户端", "HTTPClient")
|
logger.warning("在测试环境中创建临时HTTP客户端", "HTTPClient")
|
||||||
_client = httpx.AsyncClient(
|
_client = get_async_client(
|
||||||
headers=get_user_agent(),
|
headers=get_user_agent(),
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user