serpapi / google-search-results-python

Google Search Results via SERP API pip Python Package
MIT License
596 stars 97 forks source link

Exception not handled on SerpApiClient.get_json #43

Open danielperezefremova-tomtom opened 1 year ago

danielperezefremova-tomtom commented 1 year ago

I am experiencing unexpected behaviors when getting thousands of queries. For some reason, sometimes the API returns an empty response. It happens at random (1 time out of 10000 perhaps).

When this situation happens, the method SerpApiClient.get_json does not handle the empty response. In consecuence, the json.loads() raises an exception causing a JSONDecodeError.

I attach an image to clarify the issue.

issue

It seems a problem with the API service. Not sure if the problem should be solved with an Exception handling, handling the code 204 (empty response), or if there is any bug with servers.

to reproduce the exception:

import json json.loads('') Do you recommend any guidelines to handle the problem in the meanwhile you review the issue on the source code?

Thanks.

ilyazub commented 1 year ago

Thanks for raising this question.

Please share an extra information so we can investigate this issue: