You most check vaule geolocator.geocode(
If
i
).If
i
is not found location
will return None.geolocator = Nominatim()
can be set before you loop.>>> from geopy.geocoders import Nominatim >>> geolocator = Nominatim() >>> location = geolocator.geocode("oslo") >>> location Location(Oslo, 26, Norge, (59.9132694, 10.7391112, 0.0)) >>> >>> location.address 'Oslo, 26, Norge' >>> # If give a wrong adress >>> location = geolocator.geocode("___") >>> repr(location) 'None' >>> location.address Traceback (most recent call last): File "<string>", line 301, in runcode File "<interactive input>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'address'