You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置JFrog Artifactory代理后Rust Cargo拉取依赖失败求助

解决Cargo通过Artifactory代理crates.io时的索引拉取失败问题

问题现象

按Artifactory「Set me up」指引配置Config.toml后,Cargo无法完成任何包安装操作:

  • 开启net.git-fetch-with-cli = true时,报错:
Updating `artifactory` index
fatal: protocol error: bad pack header
error: failed to fetch `https://<AF_URL>/artifactory/git/crates-io-cargo-proxy.git`

Caused by:
  process didn't exit successfully: `git fetch --force --update-head-ok 'https://artifacts.rbi.tech/artifactory/git/crates-io-cargo-proxy.git' '+HEAD:refs/remotes/origin/HEAD'` (exit status: 128)
  • 关闭该配置时,报错:
Updating `artifactory` index
warning: spurious network error (2 tries remaining): early EOF; class=Net (12); code=Eof (-20)
warning: spurious network error (1 tries remaining): early EOF; class=Net (12); code=Eof (-20)
error: failed to fetch `https://<AF_URL>/artifactory/git/crates-io-cargo-proxy.git`

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here

Caused by:
  early EOF; class=Net (12); code=Eof (-20)

排查与解决步骤

1. 校验Artifactory代理仓库配置

  • 确认Artifactory中创建的是Cargo Registry类型的代理仓库,而非普通Git代理仓库
  • 检查仓库的「Remote Repository URL」是否准确设置为https://crates.io
  • 直接访问Artifactory的Cargo仓库API地址(如https://<AF_URL>/artifactory/api/crates/<你的仓库名>/),确认能正常返回JSON格式数据

2. 修正Cargo Config.toml配置

Artifactory自动生成的配置可能存在路径错误,正确配置结构如下:

[registries]
artifactory = { index = "https://<AF_URL>/artifactory/crates-io-cargo-proxy/" }

[registry]
default = "artifactory"

[net]
git-fetch-with-cli = true
  • 注意索引地址为Cargo仓库根路径,不要添加.git后缀
  • 若公司网络需要身份验证,添加凭证配置:
[registries.artifactory]
index = "https://<AF_URL>/artifactory/crates-io-cargo-proxy/"
credential-provider = "cargo:token"

随后设置环境变量CARGO_REGISTRY_TOKEN_ARTIFACTORY为你的Artifactory用户名+API密钥(格式:用户名:API密钥)

3. 清理本地Cargo缓存

执行以下命令清除旧索引和缓存,避免数据干扰:

cargo clean
rm -rf ~/.cargo/registry/index/artifactory-*

4. 检查Git与网络代理配置

  • 开启git-fetch-with-cli时,确保Git的HTTPS代理配置与公司网络一致:
    git config --global http.proxy https://<公司代理地址>:<端口>
    git config --global https.proxy https://<公司代理地址>:<端口>
    
  • 测试直接用Git克隆Artifactory的索引仓库:
    git clone https://<AF_URL>/artifactory/git/crates-io-cargo-proxy.git
    
    若克隆失败,联系Artifactory团队确认仓库权限和同步状态

5. 确认Artifactory同步状态

  • 登录Artifactory后台,查看crates.io代理仓库的「Remote Sync」状态,确认初始同步已完成
  • 若同步卡住,手动触发一次全量同步,等待同步完成后再测试Cargo命令

内容的提问来源于stack exchange,提问作者Marijan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 12:52:59