Cargo Error: failed to get `x` as a dependency of package解决方法

在使用Cargo运行或编译有依赖的程序时,可能会出现类似下面这种错误:

PS D:\hocn\Desktop\rust\a1> cargo run    
    Updating crates.io index
error: failed to get `image` as a dependency of package `a1 v0.1.0 (D:\hocn\Desktop\rust\a1)`

Caused by:
  failed to load source for dependency `image`

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)

原因

默认情况下,Cargo是通过内置的git库来下载依赖的,有时会因为验证原因导致失败;

解决办法

  • 找到.cargo目录,以Windows系统为例:C:\Users\hocn\.cargo,注意用户名;
  • 进入.cargo目录,编辑文件config.toml,如没有则创建;
  • 写入以下内容:
  • [net]
    git-fetch-with-cli = true

git-fetch-with-cli默认为false,表示使用内置的git库来下载依赖;为true时,使用git程序来下载依赖,这样就不存在验证失败的问题;

请确保你安装了git程序并正确配置;

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

本文地址: https://www.perfcode.com/p/failed-to-get-x-as-a-dependency-of-package.html

分类: 计算机技术
推荐阅读:
Rust实现字符串MD5加密 本文将使用Rust语言rust-crypto库实现字符串的MD5加密;
PySide6控件详细教程 在本教程中,我们将介绍 PySide6 中最常用的控件,包括标签、按钮、文本框、下拉框、列表框、复选框、单选框、滑块、进度条、图像控件等。
Windows10查看WiFi密码 要在Windows10上查看当前所使用的WiFi密码,只需要依次打开【控制面板】【网络和Internet】【查看网络状态和任务】【点击当前WiFi属性】【无线属性】【安全】,选中显示字符即可查看;
Linux终端给命令设置超时 在Linux系统下,有这么个场景,当你运行一条命令,你希望它在指定时间后,如果它还在运行,就自动结束它,那你可以通过这一条命令实现:
warning: implicit declaration of function 'getpid' 解决方法 在C程序中使用getpid()获取进程识别码时,可能会出现 warning: implicit declaration of function 'getpid'; did you mean 'getenv'? [-Wimplicit-function-declaration] 这样的警告信息;
WordPress如何禁用Emoji表情 由于WordPress自带的Emoji表情服务需要连接到国外服务器,国内用户访问比较慢、不稳定,影响体验,且大部分用户根本用不到;这个服务应该禁用。