简体   繁体   中英

Limit in google knowledge graph weird behaviour

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM