I'm trying to use reqwest library to download a PNG file, but when I download it I see a strange behaviour respect other programming languages like: Python.
For instance:
let content = reqwest::get("https://www.google.es/images/searchbox/desktop_searchbox_sprites302_hr.png").await?;
If I print the result as a bytes array (println!("{:?}", content.text().await?.as_bytes()
);
[ 191, 189, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 40, 0, 0, 0, 82, 8, 3, 0, 0, 0, 17, 191, 189, 102, 191, 189, 0, 0, 0, 108, 80, 76, 84, 69, 0, 0, 0, 191, 189, 191, 189, 191, 189,...]
However, the result using Python requests is:
[137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 40, 0, 0, 0, 82, 8, 3, 0, 0, 0, 17, 153, 102, 248, ...]
In the Rust version, I see a lot of 191, 189
. This sequence repeats a lot throughout the array, but in Python doesn't appear at all.
What am I doing wrong in Rust?
It's better seen as
EF, BF, BD
, which is the Unicode replacement character encoded as UTF-8. Binary data is not text data. You should not usetext
for binary data, instead usebytes
.