I am using 2 different libraries and running addresses through them. First i'm using geopy to clean and geocode addresses. Then i'm running the address through pygeocoder to see if the output is a valid address. If the output is valid, i'm appending the address to a list, which I will be returning later. If not, i'm appending "Can not be cleaned
" (this is a flask application).
Even if the address is valid, and the valid_address function of pygeocoder is returning true, the address isn't being appended to the list for some reason. It is appending "Can not be cleaned
" every time.
Here is my code:
if g.geocode(address).valid_address:
cleaned.append((str(address) + ", " + str(zipcode.lstrip()) +
", " + str(clean.latitude) + ", " + str(clean.longitude)) + '<br>')
success += 1
else:
cleaned.append('Can not be cleaned <br>')
fail += 1
except AttributeError:
cleaned.append('Can not be cleaned <br>')
fail += 1
except ValueError:
cleaned.append('Can not be cleaned <br>')
fail += 1
except GeocoderTimedOut as e:
cleaned.append('Can not be cleaned <br>')
fail += 1
What do you folks think i'm doing wrong?
Solved my problem.
I wasn't giving pygeocoder enough information. My address was in the format of street number street name. By appending the city to the end of the address and THEN validating it I solved the problem.
Unfortunately, pygeocoder works through Google Maps, which has a relatively low request limit.