Skip to content

[Bug]系统 http_proxy 环境变量干扰 localhost API 请求 #8871

@MS33834

Description

@MS33834

What happened / 发生了什么

系统设置了 http_proxy / https_proxy 环境变量后(如 Clash 代理),
AstrBot 的 Dashboard 前端和所有 API 对 localhost 的请求也通过代理发送,
导致所有本地 API 调用失败(返回空响应或超时)。

必须显式绕过代理(如 curl --noproxy '*' 或在代码中设置 NO_PROXY=localhost)
才能正常访问。

类似 issue 在一些 Python Web 框架中是已知问题,建议在启动时自动设置
NO_PROXY 包含 localhost,127.0.0.1。

Reproduce / 如何复现?

  1. 设置 https_proxy=http://127.0.0.1:7890
  2. 启动 AstrBot
  3. curl http://localhost:6185/api/auth/login → 无响应(连接超时)
  4. 注意到 curl 尝试通过代理连接 localhost
  5. 使用 curl --noproxy '*' http://localhost:6185/api/auth/login → 正常返回

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

AstrBot: v4.25.5
部署方式: Windows 本地 Python venv 直接运行
Python: 3.12.13
代理: Clash (FLClash, mixed-port 7890)

OS

Windows

Logs / 报错日志

curl -v http://localhost:6185/api/auth/login

  • Uses proxy env variable https_proxy == 'http://127.0.0.1:7890'
  • Trying 127.0.0.1:7890...
  • connect to 127.0.0.1 port 7890 failed: Connection refused
  • Failed to connect to localhost port 6185 after 0 ms

加上 --noproxy '*' 后正常:
HTTP/1.1 200 OK

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendbugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions