ERROR pip config_error ai_generated true

ERROR: Invalid value for '--trusted-host': 'example.com:8080' does not match expected pattern. Expected a hostname or IP address, optionally with a port.

ID: pip/trusted-host-flag-misuse

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2024-01-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
pip 23.3 active
pip 24.0 active
pip 24.1 active

Root Cause

The --trusted-host flag was passed a value with an incorrect format, such as a URL with scheme (https://...) or an invalid port separator, which pip cannot parse for its trusted host logic.

generic

中文

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

Official Documentation

https://pip.pypa.io/en/stable/cli/pip_install/#install-trusted-host

Workarounds

  1. 95% success Use the correct format: --trusted-host example.com:8080 (no scheme, no trailing slash)
    Use the correct format: --trusted-host example.com:8080 (no scheme, no trailing slash)
  2. 90% success If using a config file, set trusted-host = example.com:8080 in pip.conf or pip.ini
    If using a config file, set trusted-host = example.com:8080 in pip.conf or pip.ini
  3. 85% success For multiple hosts, repeat the flag: --trusted-host host1 --trusted-host host2:443
    For multiple hosts, repeat the flag: --trusted-host host1 --trusted-host host2:443

中文步骤

  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

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Pip expects only hostname:port, not a full URL; the scheme is implied.

  2. 60% fail

    The parser strictly expects a hostname without path components.