Getting decode error on get request #1893
-
I am trying to call github rest api using reqwest but getting decode error. #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let resp = client
.get("https://api.github.com/repos/neovim/neovim/releases/latest")
.header("Accept", "application/vnd.github+json")
.header("Authorization", "Bearer MY_ACCESS_TOKEN")
.header("X-GitHub-Api-Version", "2022-11-28")
.send()
.await?
.json::<serde_json::Value>()
.await?;
println!("{:#?}", resp);
Ok(())
} Here is the error Error: reqwest::Error { kind: Decode, source: Error("expected value", line: 2, column: 1) } |
Beta Was this translation helpful? Give feedback.
Answered by
seanmonstar
Jul 3, 2023
Replies: 1 comment
-
The decode error is because the response body is not valid JSON (seems like it is empty). A good next step would be to print out the response status code and headers, to see what the server is telling you. I suspect it wants a |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
thexeromin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The decode error is because the response body is not valid JSON (seems like it is empty). A good next step would be to print out the response status code and headers, to see what the server is telling you.
I suspect it wants a
user-agent
header on your request. GitHub has wanted that before.