1

According to the reference

Limit: Limits the number of entities to be returned. Maximum is 500. Default is 20. Requests with high limits have a higher chance of timing out.

but I'm facing a weird behaviour, if I try to query for example https://www.nasa.gov/ and without setting a limit (which defaults to 20) I get a response of:

{
  "error": {
    "code": 429,
    "message": "Over resource limits. Try a more restrictive request.",
    "status": "RESOURCE_EXHAUSTED"
  }
}

Now if I try with a limit of 19 or 21 I don't get any error at all.

I do realise that the error says "RESOURCE_EXHAUSTED" but it doesn't seem to be the problem here.

Note: using limit of 10 or 15 also gives the same error

This is a url to test https://developers.google.com/knowledge-graph/reference/rest/v1/?apix_params=%7B%22query%22%3A%22https%3A%2F%2Fwww.nasa.gov%2F%22%7D

Jimmar
  • 4,194
  • 2
  • 28
  • 43

1 Answers1

0

As the Google Knowledge Graph Search API notes:

Warning: This API is not suitable for use as a production-critical service. Your product should not form a critical dependence on this API.

I assume the API is not suitable for production-critical services due to errors like these. I unfortunately do not know why the error occurs, but in order to avoid your program from crashing and mitigate the effects of the error, I suggest you place your query in a try-catch block. So in Python:

import googleapiclient.discovery
try:
    service = googleapiclient.discovery.build('kgsearch', 'v1', developerKey=YOUR_API_KEY)
    search = service.entities().search(languages="en", limit=20, prefix=True, query="nasa")
    search_result = search.execute()
except:
    print("error while querying kgsearch")

Note: the error does not occur anymore (as you pointed out in the comments), however this is still a relevant issue as my program tried querying "data" and resulted in the exact same error as you described. I know the provided solution does not directly answer your question, but it was my work around it.

  • I wasn't using their packages, I was using their api endpoint directly and the issue just stopped happening for some reason. was hoping someone from their team would notice that. the problem is not how to handle the error it's why the error was occurring for a weird reason like that, thanks for trying to answer this though – Jimmar Jul 11 '22 at 18:59
  • also I'd note that this doesn't seem to happen anymore anyways – Jimmar Jul 11 '22 at 19:02