Angular produces 429 Status Code for Get Request, cURL, Python and fetch work just fine

Viewed 402

I'm working on a simple enough website and I need to perform a get request to Imgur's API. Using the following works fine:

curl -v --location --request GET 'https://api.imgur.com/3/album/WFWR56Z/images' \
--header 'Authorization: Client-ID {{clientId}}'

As does the following Python 3 code:

import requests

url = "https://api.imgur.com/3/album/WFWR56Z/images"
headers = {
  'Authorization': 'Client-ID {{clientId}}'
}

response = requests.request("GET", url, headers=headers, data=payload)

Setting up a simple example and serving it on local host using Apache and fetch also works:

    var myHeaders = new Headers();
    myHeaders.append("Authorization", "Client-ID {{clientId}}");

    var requestOptions = {
      method: 'GET',
      headers: myHeaders,
      redirect: 'follow'
    };

    fetch("https://api.imgur.com/3/album/WFWR56Z/images\n", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));

However, when I use Angular's HttpClient like so:


  constructor(private http: HttpClient) { }

  getImageLinks(): void {
    const headers = new HttpHeaders(
      {
        'Authorization': "Client-ID {{clientId}}",
      });
    this.http.get("https://api.imgur.com/3/album/WFWR56Z/images", { headers }).subscribe(data => {
      console.log(data);
    })
  }
}

I almost always get a 429 rate limit error. There are rare times when this doesn't occur, but I can't seem to identify when and why it manages to return.

1 Answers

Thanks to @Clashsoft, I downloaded the query as a cURL command and deleted the headers one by one to find the offending header:

-H 'referer: http://localhost:4200/'

Which I fixed using this: Remove http referer

Specifically, I added <meta name="referrer" content="no-referrer" /> to my index.html.

Related