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

分类: 计算机技术
推荐阅读:
为pm.max_children设置一个合理的值 pm.max_children这个值在php-fpm中至关重要;其意义为:表示php-fpm 能启动的子进程的最大数量;它能影响你网站的打开速度以及服务器的开销。
Nginx禁止使用IP直接访问 在有些场景中,我们希望访问者只能通过域名访问网站,不允许访问者直接通过IP进行访问,这一简单功能可通过配置Nginx实现。
Linux查看经常使用的命令 在Linux系统下,如果你想查看你常常使用的命令,那你运行一条命令即可实现:
Rust 宏编程 Rust 的宏编程是一种强大的元编程技术,允许您在编译时生成代码,创建自定义语法,以及进行各种代码转换。在 Rust 中,标准宏是内置于 Rust 标准库中的宏。这些宏是 Rust 语言提供的一部分,可直接在任何 Rust 代码中使用,无需额外的导入或引入其他依赖。
Python中双前导下划线__var的正确理解 近期作者发现很多Python学习者居然把双前导下划线(也就是双下划线前缀)理解成私有属性了,甚至是很多Python教程中也这么理解,这让作者感到惊讶。
Go语言获取操作系统类型 在Go语言中,你可以使用runtime包来获取操作系统类型。具体来说,你可以使用runtime.GOOS来获取操作系统类型的字符串表示。