fix: 修复无法清空 http_proxy 代理的问题 (#2434)

* 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>
This commit is contained in:
Junhua Don
2025-08-17 10:49:23 +08:00
committed by GitHub
parent 02a9769b35
commit b71000e2f3
+13 -6
View File
@@ -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):
"""