def try_geolocator_geocode(address):
"""
Tries many times to get a geolocator object from an address,
or None.
"""
if settings.TESTING:
return test_mockers.geolocator_object(address=address)
attempts = 0
while attempts < settings.GOOSE_META["max_geolocation_attempts"]:
try:
position = geolocator.geocode(
address, language=get_language().split('-')[0]
)
return position
except geopy.exc.GeopyError as e:
attempts += 1
if attempts == settings.GOOSE_META["max_geolocation_attempts"]:
debug_logger.error(
"Too much geopy errors ({}). Aborting.".format(str(e))
)
return None
评论列表
文章目录