0

Although the code has the Github token included, for some reason I am still unable to avail more GitHub Rest API quota.

I am using Reqwest for Rust to process all requests. I believe that I may be entering my token incorrectly.

The Code

        let mut headers = HeaderMap::new();
        headers.insert(USER_AGENT, HeaderValue::from_static("SBSixteen"));
        headers.insert(AUTHORIZATION,HeaderValue::from_static("github_pat_****************************************************") );
        let client = Client::builder().default_headers(headers).build().unwrap();
        let url = format!("https://api.github.com/users/{}",data.git_username);

        println!("{}", &url);

        let r1 = client.get(&url).send().await.unwrap().text().await.unwrap();
        println!("{}", &r1);

The Error

{"message":"API rate limit exceeded for ***.***.**.*. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}
thread 'tokio-runtime-worker' panicked at 'called `Option::unwrap()` on a `None` value', src\NER_EZH.rs:632:38
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I tried multiple possible combinations but I am unable to set my token correctly.

1 Answers1

2

From the GitHub API documentation, we can see that authorization tokens are expected to be presented as "bearer tokens." You just need to prefix the token with "Bearer ":

headers.insert(
    AUTHORIZATION,
    HeaderValue::from_static("Bearer github_pat_***..."),
);
cdhowie
  • 158,093
  • 24
  • 286
  • 300