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

Oracle Linux 8.7下安装Cargo Requests失败求助

问题解决:Rust requests crate 依赖冲突修复

问题根源

你使用的requests crate版本0.0.30是多年未维护的老旧版本,它依赖的hyper-native-tls v0.2.0和native-tls v0.1.0均为过时依赖,这些旧依赖要求的security-framework ^0.1.9版本已不在当前crates.io索引中,手动添加高版本依赖无效——Cargo会优先满足依赖链的版本约束,强制指定的高版本与旧依赖的低版本要求冲突。

推荐解决方案:替换为活跃维护的替代 crate

这个requests crate已停止更新,建议改用Rust生态中最常用、API设计贴近Python requests的reqwest crate:

1. 修改Cargo.toml依赖

[dependencies]
reqwest = { version = "0.11", features = ["blocking", "native-tls"] }
  • blocking特性开启同步请求模式,和Python requests使用逻辑一致
  • native-tls特性适配Oracle Linux环境的TLS支持

2. 测试基础功能

在src/main.rs中写入测试代码:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resp = reqwest::blocking::get("https://httpbin.org/get")?;
    println!("请求状态: {}", resp.status());
    let body = resp.text()?;
    println!("响应内容:\n{}", body);
    Ok(())
}

3. 构建项目

执行命令:

cargo build

正常情况下会完成依赖下载与编译。

(不推荐)坚持使用原requests crate的临时方案

若一定要使用旧版本requests,可通过补丁强制引入兼容的旧版依赖,但存在安全漏洞与兼容性风险:

[patch.crates-io]
security-framework = { git = "https://github.com/kornelski/rust-security-framework", rev = "0.1.9" }
security-framework-sys = { git = "https://github.com/kornelski/rust-security-framework", rev = "0.1.9" }

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 10:52:09