From 98d8eaee02c425c8244f85141678e44c28562c81 Mon Sep 17 00:00:00 2001 From: RC-CHN <67079377+RC-CHN@users.noreply.github.com> Date: Tue, 26 Aug 2025 21:08:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20no=5Fproxy=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=94=AF=E6=8C=81=E4=BB=A5=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E8=AE=BE=E7=BD=AE=20(#2564)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/default.py | 7 +++++++ astrbot/core/core_lifecycle.py | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 528e8f899..b299cbffb 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -103,6 +103,7 @@ DEFAULT_CONFIG = { "t2i_endpoint": "", "t2i_use_file_service": False, "http_proxy": "", + "no_proxy": ["localhost", "127.0.0.1", "::1"], "dashboard": { "enable": True, "username": "astrbot", @@ -1916,6 +1917,12 @@ CONFIG_METADATA_2 = { "type": "string", "hint": "启用后,会以添加环境变量的方式设置代理。格式为 `http://ip:port`", }, + "no_proxy": { + "description": "直连地址列表", + "type": "list", + "items": {"type": "string"}, + "hint": "在此处添加不希望通过代理访问的地址,例如内部服务地址。回车添加,可添加多个,如未设置代理请忽略此配置", + }, "timezone": { "description": "时区", "type": "string", diff --git a/astrbot/core/core_lifecycle.py b/astrbot/core/core_lifecycle.py index 069e92000..12226d9e1 100644 --- a/astrbot/core/core_lifecycle.py +++ b/astrbot/core/core_lifecycle.py @@ -52,14 +52,18 @@ class AstrBotCoreLifecycle: os.environ["https_proxy"] = proxy_config os.environ["http_proxy"] = proxy_config logger.debug(f"Using proxy: {proxy_config}") + # 设置 no_proxy + no_proxy_list = self.astrbot_config.get("no_proxy", []) + os.environ["no_proxy"] = ",".join(no_proxy_list) else: # 清空代理环境变量 if "https_proxy" in os.environ: del os.environ["https_proxy"] if "http_proxy" in os.environ: del os.environ["http_proxy"] + if "no_proxy" in os.environ: + del os.environ["no_proxy"] logger.debug("HTTP proxy cleared") - os.environ["no_proxy"] = "localhost,127.0.0.1,::1" async def initialize(self): """