Stable Diffusion 运行时 SSL 证书验证失败的解决方案
在使用 Stable Diffusion 时,您可能会遇到 SSL 证书验证失败的错误,通常显示为 ssl.SSLCertVerificationError: [ssl: certificate_verify_failed]。 这通常是因为 Python 无法验证服务器 SSL 证书的有效性。 简单地忽略证书验证并非长久之计,因为它会带来安全隐患。
一些用户尝试在 launch.py 中添加 ssl._create_default_https_context = ssl._create_unverified_context 来绕过验证,但仍然遇到错误。 这表明问题并非简单的证书信任问题,而是缺少必要的根证书。
解决方法是安装 certifi 包,它包含 Mozilla 维护的权威根证书集合。
首先,使用 pip 安装 certifi:
pip install certifi
然后,在您的 launch.py 或其他需要 HTTPS 请求的代码中,使用 certifi.where() 获取证书文件路径,并将其传递给 ssl.create_default_context():
import ssl import certifi ssl_context = ssl.create_default_context(cafile=certifi.where())
通过使用 certifi 提供的证书,Python 就能正确验证服务器的 SSL 证书,从而避免 SSL 验证失败错误。 这种方法比直接忽略证书验证更安全可靠。
以上就是Stable Diffusion SSL 证书验证失败怎么办?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号