conan remote add 的 url 必须完整包含协议(如 https://)和端口(如 :8081),缺一不可;末尾不能有多余斜杠,否则部分 artifactory 版本会返回 404。

检查conan remote add 的 URL 是否带协议和端口
Conan 客户端对 remote URL 格式敏感,不加 https:// 或漏写端口(如 :8081)会导致连接被静默拒绝,错误提示常为 ERROR: Unable to connect to ...,但实际根本没发请求。
- 正确写法:
conan remote add my-remote https://artifactory.example.com:8081/artifactory/api/conan/my-repo - 错误写法:
conan remote add my-remote artifactory.example.com/artifactory/...(缺协议)或https://artifactory.example.com/artifactory/...(若服务实际监听 8081,却没写端口) - 运行
conan remote list确认 URL 输出是否与你预期完全一致,注意末尾不能有多余斜杠(/),否则部分 Artifactory 版本会 404
验证 conan user -r 是否真正完成认证
conan user 命令成功返回 “Change user” 并不等于已通过远端鉴权——它只把凭据存进本地 ~/.conan/remotes.json 和 ~/.conan/registry.json,而实际登录需在首次操作时触发。很多用户卡在这步,误以为“登过了”。
- 执行
conan search -r my-remote "*" --raw(或任意简单包名),这是最轻量的鉴权试探;若报ERROR: Forbidden或ERROR: Bad credentials,说明认证失败 - 确认
conan user -p "your-token" -r my-remote "your-username"中的your-token是有效 API Key(非密码),且该用户在远端仓库有Deploy/Cache权限 - Docker 场景下:如果私有仓库跑在宿主机,remote URL 写
http://localhost:8081会连到容器自己;必须用http://host.docker.internal:8081(Windows/macOS 默认支持,Linux 需启动时加--add-host=host.docker.internal:host-gateway)
抓包确认请求是否发出、响应是否合法
Conan 不会打印底层 HTTP 请求细节,靠日志很难定位是网络层阻断还是服务端返回异常。直接用 curl 模拟最可靠。
- 先测基础连通性:
curl -I https://artifactory.example.com:8081/artifactory/api/conan/my-repo/v1/ping,应返回HTTP/2 200 - 再测包索引接口:
curl -H "Authorization: Bearer YOUR_TOKEN" "https://artifactory.example.com:8081/artifactory/api/conan/my-repo/v1/conans/search?q=*" | jq .,确认返回 JSON 且含results字段 - 如果
curl能通但 Conan 不行,大概率是证书问题:Conan 默认校验 SSL,私有仓库若用自签名证书,需加conan remote set-url my-remote https://... --verify-ssl=False(仅测试环境)
排查 conanfile.py 中 remote 绑定与 profile 配置冲突
Conan 允许在 conanfile.py 里硬编码 self.requires(..., remote="my-remote"),也支持全局 profile 指定默认 remote。两者混用容易导致“明明配了 remote 却走错源”。
- 运行
conan profile show default,检查输出中是否有default_remote行;若有,它会覆盖命令行-r参数(除非显式传--remote) - 检查
conanfile.py是否调用了self.requires("pkg/1.0@user/channel", remote="other-remote")—— 这个remote名必须和conan remote list中存在的名称完全一致,大小写敏感 - 临时绕过所有配置:用
conan install . --build=missing -r my-remote --no-cache强制指定 remote 并禁用缓存,排除 profile 干扰
conan user 有效得多。











