def try_geolocator_reverse(coords):
"""
Tries many times to get a geolocator object from coordinates,
or None.
"""
if settings.TESTING:
return test_mockers.geolocator_object(coords=coords)
attempts = 0
while attempts < settings.GOOSE_META["max_geolocation_attempts"]:
try:
position = geolocator.reverse(
coords, 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
评论列表
文章目录