ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

用户在启动 Stable Diffusion WebUI Forge 时,通过 bat 脚本(如 webui-user.bat )或 Python 指令触发,Gradio 在初始化时检测到 localhost 不可访问,抛出此错误。

ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

快速结论:该报错通常出现在运行 Stable Diffusion WebUI Forge 时,Python 的代理(proxy)设置导致本地 localhost 无法访问,从而触发 Gradio 要求创建可共享链接。优先排查系统环境变量中的代理设置,或尝试调整 no_proxy 配置。

问题场景

用户在启动 Stable Diffusion WebUI Forge 时,通过 bat 脚本(如 webui-user.bat)或 Python 指令触发,Gradio 在初始化时检测到 localhost 不可访问,抛出此错误。

报错原文

ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

原因分析

最可能原因是操作系统或网络环境中设置了 HTTP 代理环境变量(如 http_proxyhttps_proxy),导致 Gradio 在尝试连接本地 localhost 时会经过代理,而代理未正确路由本地流量,从而拒绝或无法连接。Gradio 要求 localhost 直接可达,否则只能通过 share=True 创建公网隧道。

也可能原因:系统 no_proxy 环境变量未包含 localhost、127.0.0.1、::1 等本地地址。

环境排查

  • 确认系统环境变量中是否存在 http_proxyhttps_proxy(可通过 echo %http_proxy%env | grep -i proxy 查看)
  • 确认 no_proxy 环境变量是否设置,且是否包含 localhost127.0.0.1::1
  • 确认运行的 webui-user.bat 脚本是否包含 set no_proxy=localhost,127.0.0.1,::1 配置

解决步骤

  1. 手动编辑启动脚本:使用文本编辑器(如 VS Code、Notepad++)打开 webui-user.bat,在 Python 命令执行前添加:
    set no_proxy=localhost, 127.0.0.1, ::1
    保存并重新运行脚本。
  2. 临时取消代理环境变量:在启动 WebUI 前,在 bat 脚本或终端中使用 set http_proxy=set https_proxy= 清除类似代理变量(取决于实际环境)。
  3. 替代方案(推测):可尝试降级 pydantic 版本至 2.10.6(参见相关 issue),但此方案未经原 issue 直接验证,为其他类似问题中的解决方式。

验证方法

重新启动 Stable Diffusion WebUI Forge 后,观察报错是否消失,Gradio 正常显示本地访问链接(如 http://127.0.0.1:7860),且 WebUI 界面可正常加载。

参考来源

lllyasviel/stable-diffusion-webui-forge #1479

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 8079

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注