Google Search API fails sporadically with "502 Bad Gateway"
I heard about Google's web service interface to the search database back when it was released, but today was my first attempt to use it. I'm trying to learn python, but the SOAP toolkits for python seem to be in a state of flux so I switched back to C# rather than figure out which python libraries to download.
I experienced two problems, one minor and one major. The doSearch method takes a bunch of strings, and if you pass null in, you get back weird errors talking about no signature match and java.lang.String. Passing String.Empty fixes that.
The second problem is that, requests to search sporadically fail with "502: Bad Gateway". From my googling (ah, the irony) for a solution, this has been a problem since January 2006, and is still unsolved.
The solution on the forums seems to be catch the exception and try again; I didn't expect that to work, but it did. I wrote a console app that sent the same string to the gateway 30 times, and it seemed to randomly error out. A snippet of the output is below:
12:27:14.593 - The request failed with HTTP status 502: Bad Gateway.
12:27:19.046 - Success, found 782000 items.
12:27:32.625 - Success, found 782000 items.
12:27:35.000 - Success, found 782000 items.
12:27:35.984 - The request failed with HTTP status 502: Bad Gateway.
12:27:39.843 - Success, found 782000 items.
12:27:42.593 - Success, found 782000 items.
This makes this obviously unsuitable for anything more than playful experimentation, but since the API doesn't return ads, I guess Google doesn't care.