From b71000e2f315a2bdfe1265c3ded4dcb9535147cf Mon Sep 17 00:00:00 2001 From: Junhua Don <1724728802@qq.com> Date: Sun, 17 Aug 2025 10:49:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=B8=85=E7=A9=BA=20http=5Fproxy=20=E4=BB=A3=E7=90=86=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#2434)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复无法清空http_proxy代理的问题 * perf: 将“127.0.0.1”和“::1”添加到“no_proxy”以确保所有本地流量绕过代理。 Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --------- Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- astrbot/core/core_lifecycle.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/astrbot/core/core_lifecycle.py b/astrbot/core/core_lifecycle.py index eccffbd64..069e92000 100644 --- a/astrbot/core/core_lifecycle.py +++ b/astrbot/core/core_lifecycle.py @@ -47,12 +47,19 @@ class AstrBotCoreLifecycle: self.db = db # 初始化数据库 # 设置代理 - if self.astrbot_config.get("http_proxy", ""): - os.environ["https_proxy"] = self.astrbot_config["http_proxy"] - os.environ["http_proxy"] = self.astrbot_config["http_proxy"] - if proxy := os.environ.get("https_proxy"): - logger.debug(f"Using proxy: {proxy}") - os.environ["no_proxy"] = "localhost" + proxy_config = self.astrbot_config.get("http_proxy", "") + if proxy_config != "": + os.environ["https_proxy"] = proxy_config + os.environ["http_proxy"] = proxy_config + logger.debug(f"Using proxy: {proxy_config}") + else: + # 清空代理环境变量 + if "https_proxy" in os.environ: + del os.environ["https_proxy"] + if "http_proxy" in os.environ: + del os.environ["http_proxy"] + logger.debug("HTTP proxy cleared") + os.environ["no_proxy"] = "localhost,127.0.0.1,::1" async def initialize(self): """