Updating crates.io index 出现错误解决方法

在向Rust项目添加依赖后尝试运行或编译,cargo管理工具会尝试更新crates.io index,当出现git配置错误可能会出现类似以下的错误:

update crates.io index
    Updating crates.io index
error: failed to get `rust-crypto` as a dependency of package `rust v0.1.0 (D:\hocn\Desktop\src\rust)`

Caused by:
  failed to load source for dependency `rust-crypto`

Caused by:
  Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to authenticate when downloading repository: git@github.com:rust-lang/crates.io-index

  * attempted ssh-agent authentication, but no usernames succeeded: `git`

  if the git CLI succeeds then `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  error authenticating: unable to connect to agent pipe; class=Ssh (23)

出现这样的错误,原因可能是本地crates.io index损坏,cargo尝试更新时,git的错误配置导致无法获取新的crates.io index

这里不讨论如何去配置git,只研究如何获取最新的crates.io index

解决方法

首先将rust更新到最新版,如果对版本有要求,可跳过这一步;

rustup update

运行命令 rustup update

然后找到C:\Users\xxxx\.cargo\registry目录(这里以Windows系统为例,xxxx是你的用户名);

进入index文件夹,你会看到一个这样的目录(名称可能不一样):

update crates.io index

该目录就是一个github仓库,远程地址为:https://github.com/rust-lang/crates.io-index

你要做的是将该目录的名称记录下来,这里是github.com-1ecc6299db9ec823,然后将该目录删除;

将github仓库克隆到该目录,你可使用git进行克隆,或直接下载仓库到本地;

update crates.io index

完成后将目录名替换成github.com-1ecc6299db9ec823,注意目录结构;

此时再运行或编译程序将不会再报错;

原创内容,如需转载,请注明出处;

本文地址: https://www.perfcode.com/p/updating-crates-io-index.html

分类: 计算机技术
推荐阅读:
C程序判断一个数是否为质数,并打印100以内的质数 在本文中,我们将使用C语言来判断一个整数是否为质数,并打印100以内的所有质数;
Python使用langid库来识别字符串语言 python使用 langid 库来实现识别字符串是什么语言;langid 是第三方库,需要我们自己安装
Python使用webbrowser模块来实现弹出一个网页 如果你希望在别人运行你的程序时弹出一个指向自己网站的页面,你可以通过以下代码来实现:
没有main()函数的C语言程序 有两种方法可以不添加main()函数来运行C语言程序,第一种用#define预处理指令,第二种是使用-nostartfiles编译选项;
xxxx is not in the sudoers file. This incident will be reported. 解决方法 使用sudo命令时出现xxxx is not in the sudoers file. This incident will be reported. 这里的xxxx是你的用户名;出现这个提示通常是用户名没有写入到sudoers文件中;
PySide6:No module named 'QWebEngineView' 解决方法 如果你在使用PySide6时碰到No module named 'QWebEngineView' 或 No module named 'PySide6.QtWebEngineWidgets' 的错误提示,请将PySide6更新到最新版本,因为该组件在某些比较老的版本还未得到支持;