AnsweredAssumed Answered

Google Geocoding API returns “OVER_QUERY_LIMIT” for some addresses, seemingly at random

Question asked by MatthewLeonard on Mar 6, 2018
Latest reply on Mar 8, 2018 by MatthewLeonard

I'm using a Python script to send a list of addresses to the Google Geocoding API and parse the JSON results to give me a text list of coordinates. My problem is: For some addresses in the list, the API fails to return coordinates and instead returns the status "OVER_QUERY_LIMIT", but then it will continue to process more addresses successfully. For example, in a list of 200 addresses, I will get "OVER_QUERY_LIMIT" for roughly 40 or 60 of them, in no particular order, and the rest will be fine. But if I run the script again with the same list of addresses, some of those which failed the first time will return a result with coordinates like they should, with status "OK", but randomly differentaddresses in the list will fail. Does anyone have a clue why this would happen?

The script uses a loop to send each address as an API request one at a time, including a pause between each request to satisfy Google's limit on requests per second. And the total number of requests I'm sending should be well below Google's cap on free requests per day. So I don't believe I'm really going "over query limit" - also note that I am able to continue getting successful results after the ones that fail. So what could be making some addresses return this status at random?

Here's the script for anyone who's curious:

import urllib, jsonimport sys, timeimport pprint # specify input addresses as a list (for simplicity of demonstration):addresses = [   'address 1'   'address 2'   'address 3 etc.'    ]# I removed the real addresses for privacy, but you get the ideafor add in addresses:    time.sleep(.1)    prefix = 'https://maps.googleapis.com/maps/api/geocode/json?'    data = urllib.urlencode({"address" : add})    url = prefix+data     gresp = urllib.urlopen(url)    jresp = json.loads(gresp.read())    if jresp['status'] == 'OK':        lat = jresp['results'][0]['geometry']['location']['lat']        lon = jresp['results'][0]['geometry']['location']['lng']        print (str(lat)+"; "+str(lon))    else:        print jresp['status']

My results typically look something like this (for example):

33.782041; -84.416123233.8111927; -84.3640217OVER_QUERY_LIMIT33.7980347; -84.369196433.7396419; -84.371720533.7601601; -84.3955309OVER_QUERY_LIMIT33.7794269; -84.367583633.760549; -84.38706133.80361; -84.394133733.814729; -84.3910812OVER_QUERY_LIMIT OVER_QUERY_LIMIT33.7977534; -84.407681233.811963; -84.395412OVER_QUERY_LIMIT OVER_QUERY_LIMIT OVER_QUERY_LIMIT33.7682217; -84.384999233.8480993; -84.428437833.9229844; -84.3982854

Any insight would be appreciated!

Outcomes