Source: https://swgbar.com/zh-CN/guides/fix-python-docker-certificate-verify-failed-x509-mac/
Language: zh-CN

# 修复 Mac 上 Python 'CERTIFICATE\_VERIFY\_FAILED' 与 Docker 'x509: certificate signed by unknown authority' 报错

解决在 Zscaler、Netskope、Cloudflare 等企业 SWG 下，macOS 中 Python、pip、uv、requests 报 \[SSL: CERTIFICATE\_VERIFY\_FAILED\] 以及 Docker Desktop 报 x509: certificate signed by unknown authority 的问题。

SWG bar · 更新日期 2026年11月24日

在部署了开启 SSL 检查的安全 Web 网关（Zscaler、Cloudflare WARP、Netskope、Cisco Umbrella、Palo Alto 或 Fortinet）的公司 MacBook 上，\*\*Python（`pip`、`uv`、`requests`、`conda`）\*\*经常报错 `ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] unable to get local issuer certificate`，而 **Docker Desktop** 在执行 `docker pull` 或 `docker build` 时也会报 `x509: certificate signed by unknown authority`。

这两个报错源于同一个原因：macOS 系统钥匙串信任公司通过 MDM 安装的 SWG 根证书，但 **Python 的 `certifi` 证书包**与 **Docker Desktop 的 Linux 虚拟机**各自维护着独立的证书存储。你可以将原始报错粘贴到免费的 [SWG 与 SSL 报错解码器](<https://swgbar.com/zh-CN/tools/tls-error-decoder/>)，或直接应用下方验证过的修复步骤。

## 1\. 在 macOS 上导出企业 SWG Root CA PEM 证书

先通过 **SWG bar → 证书**或 `openssl s_client -connect pypi.org:443 -servername pypi.org </dev/null 2>/dev/null | openssl x509 -noout -issuer` 查明拦截 CA 的名称，然后干净地导出至 `~/.certs/corporate-swg-root.pem`：

```
mkdir -p "$HOME/.certs"
# 将 "Zscaler" 替换为 Cloudflare、goskope、Cisco Umbrella、Fortinet 或贵公司 CA 名称
security find-certificate -c "Zscaler" -p /Library/Keychains/System.keychain > "$HOME/.certs/corporate-swg-root.pem"
```

_（提示：对于 Python `requests` / `pip`，需要将企业根证书与 `certifi` 合并为一个组合证书包，或启用系统原生信任，才能确保公共根证书与企业 CA 同时生效。）_

## 2\. 修复 Python、pip、uv 与 requests（`CERTIFICATE_VERIFY_FAILED`）

### 最快的现代方案（直接使用 macOS 系统钥匙串）

*   **针对 `uv`（Astral）**：
    
    ```
    export UV_NATIVE_TLS=true
    ```
    
*   **针对 `pip` 24.2+**：
    
    ```
    pip config set global.use-feature truststore
    ```
    
*   **针对 Python `requests` / `httpx` / `urllib`（将企业根证书追加至 `certifi`）**：
    
    ```
    CERTIFI_CA=$(python3 -c "import certifi; print(certifi.where())")
    cat "$CERTIFI_CA" "$HOME/.certs/corporate-swg-root.pem" > "$HOME/.certs/python-combined-ca.pem"
    echo 'export SSL_CERT_FILE="$HOME/.certs/python-combined-ca.pem"' >> ~/.zshrc
    echo 'export REQUESTS_CA_BUNDLE="$HOME/.certs/python-combined-ca.pem"' >> ~/.zshrc
    source ~/.zshrc
    ```
    

## 3\. 修复 Docker Desktop（`x509: certificate signed by unknown authority`）

Docker 在 macOS 上会在**两个独立位置**失败——只修其中一个，另一个仍会报错：

1.  **Docker 守护进程（`docker pull` / `docker login`）**：macOS 版 Docker Desktop 启动时会自动从系统钥匙串同步受信任的根证书。如果公司是在 Docker 运行期间推送的新 SWG 证书，请**彻底退出并重启 Docker Desktop**（或在“钥匙串访问”中确认该根证书已设为_始终信任_）。如果使用 Colima 或 OrbStack，请将 `corporate-swg-root.pem` 复制进 Linux 虚拟机的 `/usr/local/share/ca-certificates/` 目录并运行 `update-ca-certificates`。
2.  **`docker build` 容器构建内部（构建过程中执行 `apt-get`、`pip`、`npm`、`curl`）**：容器**不会**继承 macOS 钥匙串。需要在构建时将企业 CA 作为 build secret 传入，或在构建阶段复制并更新信任库：

```
COPY corporate-swg-root.pem /usr/local/share/ca-certificates/corporate-swg.crt
RUN update-ca-certificates
```

## 4\. 免去维护 CA 证书包的麻烦：在 Mac 上按域名绕过 SWG

如果你处于允许单域名绕过的获授权网络环境中，[SWG bar](<https://swgbar.com/zh-CN/install/>) 可以让你精准确认究竟是哪些包仓库或镜像源（`pypi.org`、`files.pythonhosted.org`、`registry-1.docker.io`、`auth.docker.io`）正在被解密，并一键按主机名绕过——彻底消除容器与虚拟环境之间的 CA 证书不匹配问题：

```
swgbar probe pypi.org
swgbar bypass enable pypi.org
swgbar bypass enable files.pythonhosted.org
```

完整配置说明请参阅[如何在 Mac 上绕过 SWG](<https://swgbar.com/zh-CN/guides/how-to-bypass-swg/>)以及[Mac 在 SWG 下的 Homebrew、Docker、Python 与 Node.js CA 信任配置](<https://swgbar.com/zh-CN/guides/homebrew-docker-python-node-ca-trust-swg-macos/>)。

macOS 14+ · Apple Silicon

## 别再盲猜公司 SWG 解密了哪些域名。

SWG bar 在 Mac 菜单栏实时检测 HTTPS 解密，并支持单域名一键绕过，同时保持公司 VPN 与 SSO 正常工作。

[$0 开启 14 天免费试用](<https://swgbar.com/releases/2.4.12/SWGBar-macOS-arm64.pkg>) [诊断 TLS 报错](<https://swgbar.com/zh-CN/tools/tls-error-decoder/>) [免费 Chrome 扩展](<https://chromewebstore.google.com/detail/bidclnlfneemkkdeanlcbpjfdalelmbf>)

## 继续阅读

*   [如何在 Mac 上绕过 SWG（单域名一键绕过与 CLI 命令）](<https://swgbar.com/zh-CN/guides/how-to-bypass-swg/>)
*   [如何在 Mac 上绕过 SSL 检查（企业 SWG 单域名绕过指南）](<https://swgbar.com/zh-CN/guides/bypass-ssl-inspection-mac/>)
*   [如何在 macOS 上绕过 HTTPS 与 TLS 检查（Break-and-Inspect 指南）](<https://swgbar.com/zh-CN/guides/bypass-https-tls-inspection-mac/>)
*   [如何在 Mac 上绕过企业代理与 SWG SSL 检查](<https://swgbar.com/zh-CN/guides/bypass-corporate-proxy-ssl-inspection-mac/>)
*   [如何判断我的电脑是否被 SWG 劫持（Mac 上检测 HTTPS/SSL 检查）](<https://swgbar.com/zh-CN/guides/detect-https-inspection/>)
*   [如何检查公司或办公 Mac 是否正在拦截 HTTPS（SSL 检查排查）](<https://swgbar.com/zh-CN/guides/check-if-work-mac-intercepting-https/>)
*   [公司在工作 Mac 上能看到我的浏览记录、无痕模式和个人账号吗？](<https://swgbar.com/zh-CN/guides/can-employer-see-browsing-history-incognito-work-mac/>)
*   [Mac SSL 检查检测工具：菜单栏实时侦测 HTTPS 拦截](<https://swgbar.com/zh-CN/guides/ssl-inspection-checker-mac/>)
*   [Mac 上的 Zscaler SSL 检查：如何检测并按域名绕过](<https://swgbar.com/zh-CN/guides/zscaler-ssl-inspection-bypass-mac/>)
*   [如何在 Mac 上关闭或绕过 Zscaler（当防篡改保护将其锁定时）](<https://swgbar.com/zh-CN/guides/disable-turn-off-zscaler-on-mac/>)
*   [Mac 上的 Cloudflare WARP 与 Zero Trust TLS 检查：检测与绕过](<https://swgbar.com/zh-CN/guides/cloudflare-warp-tls-inspection-mac/>)
*   [Mac 上的 Netskope SSL 检查：检测解密与单域名绕过指南](<https://swgbar.com/zh-CN/guides/netskope-ssl-inspection-bypass-mac/>)
*   [Mac 上的 Cisco Umbrella SSL 检查：检测解密并按域名绕过](<https://swgbar.com/zh-CN/guides/cisco-umbrella-ssl-inspection-bypass-mac/>)
*   [Mac 上的 Palo Alto GlobalProtect 与 Prisma Access SSL 解密：检测与绕过](<https://swgbar.com/zh-CN/guides/palo-alto-globalprotect-prisma-ssl-decryption-mac/>)
*   [Mac 上的 Fortinet FortiClient 与 FortiGate（Fortinet\_CA\_SSL）检查：检测与绕过](<https://swgbar.com/zh-CN/guides/fortinet-forticlient-ssl-inspection-bypass-mac/>)
*   [修复 Mac 上 Git 与 npm 的 'unable to get local issuer certificate' / SELF\_SIGNED\_CERT\_IN\_CHAIN 报错](<https://swgbar.com/zh-CN/guides/fix-git-npm-unable-to-get-local-issuer-certificate-mac/>)
*   [修复 Mac 上 GitHub Copilot、OpenAI Codex 与 Gemini CLI 的 SSL 证书错误（Zscaler / SWG）](<https://swgbar.com/zh-CN/guides/fix-codex-copilot-gemini-cli-ssl-certificate-error-mac/>)
*   [SWG bar 中的“已确认”与“疑似”HTTPS 检查状态解析](<https://swgbar.com/zh-CN/guides/confirmed-vs-suspected-https-inspection/>)
*   [在 SWG bar 中检查中间人根证书与签发机构](<https://swgbar.com/zh-CN/guides/inspect-mitm-root-certificates-macos/>)
*   [Mac 上的企业 SWG 与 MDM HTTPS 解密检查解析](<https://swgbar.com/zh-CN/guides/enterprise-swg-https-inspection-macos/>)
*   [SWG 绕过与 TLS 解密例外（Break-and-Inspect）对比](<https://swgbar.com/zh-CN/guides/swg-bypass-vs-tls-exception/>)
*   [在 Mac 上为多域名 Web 应用、SSO、CDN 与 API 配置 SWG 绕过](<https://swgbar.com/zh-CN/guides/multi-domain-sso-api-cdn-swg-bypass/>)
*   [排查 Mac 上 SWG 绕过的“恢复中”“已暂停”与连接错误](<https://swgbar.com/zh-CN/guides/troubleshoot-swg-bypass-recovering-paused-macos/>)
*   [macOS VPN 虚拟网卡与 SWG HTTPS 检查对比](<https://swgbar.com/zh-CN/guides/macos-vpn-virtual-interface-vs-swg-inspection/>)
*   [为什么证书固定（Pinning）应用与 mTLS 在 SWG 检查下会失效](<https://swgbar.com/zh-CN/guides/certificate-pinning-mtls-swg-inspection-macos/>)
*   [修复 Mac 终端 CLI 与 AI 工具中的 SWG TLS/SSL 证书错误](<https://swgbar.com/zh-CN/guides/swg-tls-certificate-errors-macos/>)
*   [Mac 在 SWG 下的 Homebrew、Docker、Python 与 Node.js CA 信任配置](<https://swgbar.com/zh-CN/guides/homebrew-docker-python-node-ca-trust-swg-macos/>)
*   [修复 Mac 上 Claude Code 与 Cursor 的 'unable to get local issuer certificate' 报错（SWG 与 MCP）](<https://swgbar.com/zh-CN/guides/ai-coding-agents-claude-code-cursor-swg-macos/>)
*   [在 Mac 上使用 openssl 与 security verify-cert 验证 TLS 证书](<https://swgbar.com/zh-CN/guides/verify-tls-certificates-openssl-security-verify-cert-macos/>)
*   [SWG bar 权限、本地隐私与 TLS 探测限额说明](<https://swgbar.com/zh-CN/guides/macos-network-extension-privacy-probe-limits/>)
*   [SWG bar 如何检查 HTTPS 解密](<https://swgbar.com/zh-CN/how-it-works/>)
*   [下载并安装 Mac 版 SWG bar（macOS 14+）](<https://swgbar.com/zh-CN/install/>)
*   [检测 SSL 与 HTTPS 检查的 Chrome 扩展（SWG bar 配套插件）](<https://swgbar.com/zh-CN/chrome-extension/>)
*   [SWG bar CLI 使用指南](<https://swgbar.com/zh-CN/cli/>)
*   [SWG bar MCP 使用指南](<https://swgbar.com/zh-CN/mcp/>)
*   [SWG bar 版本信息](<https://swgbar.com/zh-CN/releases/>)
*   [关于 SWG bar](<https://swgbar.com/zh-CN/about/>)
