Home:ALL Converter>Intermittent Http Error 403 When Invoking Google Custom Search API

Intermittent Http Error 403 When Invoking Google Custom Search API

Ask Time:2015-02-27T08:55:35         Author:Shikhar Mishra

Json Formatter

I'm getting the following error intermittently when invoking the custom search api from a server side setup:

HttpError 403 when requesting https://www.googleapis.com/customsearch/v1?q=John+Doe+john%40simpler.com&alt=json&cx=&key= returned "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.

I'm using a server api key, and have confirmed that the configured server ip address is correct. And about 50% of the time my request come back fine, too. I'm issuing the request from the server like this:

service = build("customsearch", "v1",
                developerKey=api_key)

custom_search_context = <my_context>

res = service.cse().list(
    q=search_query_string,
    cx=custom_search_context,
).execute()

My requests per sec are well with in the configured limit of 10/sec and daily purchased limit of 5000 requests.

One more thing I noticed is that Google counts a forbidden request towards the daily limit, too.

Any pointers on why I'm being presented with the error only intermittently would be very helpful

Author:Shikhar Mishra,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28755710/intermittent-http-error-403-when-invoking-google-custom-search-api
yy