# 错误：'--trusted-host' 的值无效：'example.com:8080' 不符合预期模式。期望主机名或 IP 地址，可选带端口。

- **ID:** `pip/trusted-host-flag-misuse`
- **领域:** pip
- **类别:** config_error
- **错误码:** `ERROR`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

--trusted-host 标志传递的值格式不正确，例如带有 scheme 的 URL（https://...）或无效的端口分隔符，pip 无法解析以用于其受信任主机逻辑。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 23.3 | active | — | — |
| pip 24.0 | active | — | — |
| pip 24.1 | active | — | — |

## 解决方案

1. ```
   使用正确格式：--trusted-host example.com:8080（无 scheme，无尾部斜杠）
   ```
2. ```
   如果使用配置文件，在 pip.conf 或 pip.ini 中设置 trusted-host = example.com:8080
   ```
3. ```
   对于多个主机，重复该标志：--trusted-host host1 --trusted-host host2:443
   ```

## 无效尝试

- **** — Pip expects only hostname:port, not a full URL; the scheme is implied. (80% 失败率)
- **** — The parser strictly expects a hostname without path components. (60% 失败率)
