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

分类: 计算机技术
推荐阅读:
Python调用Windows API的一个简单例子 Python调用WINDOWS API的方法有多种,本文将使用Python 调用WINDOWS API来获取系统的版本信息。
解决Golang中cannot refer to unexported name xxxx这类错误 在Golang中,碰到cannot refer to unexported name xxxx,这类错误,通常是你调用了一个包内不存在的函数导致的;
C程序生成长度32的随机十六进制字符串 在C语言中生成一个长度为32的十六进制随机字符串;大致方法为,生成一个十进制的数,然后转换成十六进制字符;
MySQL INTERVAL 时间间隔表达式 时间间隔表达式表示一个时间的间隔,通常用于时间的计算;语法如下:
PySide6 exec()函数详细教程 PySide6.QtWidgets.Application类的exec()函数使程序进入Qt主事件循环并等待直到调用exit()函数,然后返回调用exit()时设置的值,如果调用的是quit()函数,则是0;此处的exit()和quit()函数是QApplication类的成员函数;
Linux终端模拟打字(逐字符显示) 在Linux系统下,你可以使用一条命令来实现像电影里的效果,让字符逐个显示: