Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23390

What is the Rust reqwest equivalent of the following Python requests code?

$
0
0

I am trying to do a Basic Authentication GET, ignoring certificate validation, using reqwests.

I have following Python requests code, which works:

import requestsfrom requests.auth import HTTPBasicAuthsession = requests.sessions.Session()session.auth = HTTPBasicAuth("username", "password")session.verify = Falseresponse = session.get("http://myurl.com/myapi")

I want to do the same thing using Rust reqwest.So far, I have the following:

use reqwestlet url = "http://myurl.com/myapi";let response = reqwest::Client::builder()  .danger_accept_invalid_certs(true)  .build()  .unwrap()  .get(&url)  .basic_auth("username", Some("password"))  .send()  .await?;

The Python requests call works as expected. However, I get the following response from Rust:

Error: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("myurl.com")), port: None, path: "myapi", query: None, fragment: None }, source: Error { kind: Connect, source: Some("unsuccessful tunnel") } }

If I need to produce more code (I can't provide the actual URL), please let me know.


Viewing all articles
Browse latest Browse all 23390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>