python - GeocoderServiceError for geopy -


when using geopy calculate distances between 2 addresses based on longitude , latitude, works fine on individual pair of data. when there more data, gives me error:

file "/library/python/2.7/site-packages/geopy/geocoders/osm.py", line 193, in geocode self._call_geocoder(url, timeout=timeout), exactly_one file "/library/python/2.7/site-packages/geopy/geocoders/base.py", line 171, in _call_geocoder raise geocoderserviceerror(message) geopy.exc.geocoderserviceerror: urlopen error [errno 65] no route host

do know how can avoid problem?

my code simple: (the data input has many pairs of data)

from geopy.geocoders import nominatim geopy.distance import vincenty  def calculate_distance(add1, add2):     geolocator = nominatim()      location1 = geolocator.geocode(add1)     al1 = (location1.latitude, location1.longitude)      location2 = geolocator.geocode(add2)     al2 = (location2.latitude, location2.longitude)      distce = vincenty(al1, al2).miles     return distce 

def get_level1_locations(lat_lng):     elems = lat_lng.split(',')     url = "http://maps.googleapis.com/maps/api/geocode/json?"     url += "latlng=%s,%s&sensor=false" % (float(elems[0]), float(elems[1]))     v = urlopen(url).read()     j = json.loads(v)     if len(j['results'])>0:       components = j['results'][0]['address_components']       location_list=[]       c in components:           if "locality" in c['types']:             location_list.append(c['long_name'])           if "administrative_area_level_1" in c['types']:             location_list.append(c['long_name'])           if "country" in c['types']:             location_list.append(c['long_name'])       location = ', '.join(filter(none, location_list))       return location     return '' 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -