Dimitris Tagkoulis
Dimitris Tagkoulis

Reputation: 13

How to fix "GeocoderUnavailable: Service not available" error when Nonimatim is up

I want to add coordinates to street names i have downloaded from England's Land Registry but Nonimatim keeps outpouting this error GeocoderUnavailable: Service not available.

I have tried slowing down the requests but still it doesnt help at all.

from geopy.geocoders import Nominatim
from geopy.distance import vincenty

geolocator = Nominatim(user_agent="email")
nom=Nominatim(domain='localhost:8080', scheme='http')`

affordable['city_coord'] = affordable['Street'].apply(geolocator.geocode).apply(lambda x: (x.latitude, x.longitude))`

The outpout should be a "city_coord" column with latidue and longitude of every road so i can split it into two later but the actual output is this error:

    OSError                                   Traceback (most recent call last)
    /opt/conda/envs/DSX-Python35/lib/python3.5/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
       1253             try:
    -> 1254                 h.request(req.get_method(), req.selector, req.data, headers)
       1255             except OSError as err: # timeout error

    /opt/conda/envs/DSX-Python35/lib/python3.5/http/client.py in request(self, method, url, body, headers)
       1106         """Send a complete request to the server."""
    -> 1107         self._send_request(method, url, body, headers)
       1108 

    /opt/conda/envs/DSX-Python35/lib/python3.5/http/client.py in _send_request(self, method, url, body, headers)
       1151             body = _encode(body, 'body')
    -> 1152         self.endheaders(body)
       1153 

    /opt/conda/envs/DSX-Python35/lib/python3.5/http/client.py in endheaders(self, message_body)
       1102             raise CannotSendHeader()
    -> 1103         self._send_output(message_body)
       1104 

    /opt/conda/envs/DSX-Python35/lib/python3.5/http/client.py in _send_output(self, message_body)
        933 
    --> 934         self.send(msg)
        935         if message_body is not None:

    /opt/conda/envs/DSX-Python35/lib/python3.5/http/client.py in send(self, data)
        876             if self.auto_open:
    --> 877                 self.connect()
        878             else:

    /opt/conda/envs/DSX-Python35/lib/python3.5/http/client.py in connect(self)
       1252 
    -> 1253             super().connect()
       1254 

    /opt/conda/envs/DSX-Python35/lib/python3.5/http/client.py in connect(self)
        848         self.sock = self._create_connection(
    --> 849             (self.host,self.port), self.timeout, self.source_address)
        850         self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

    /opt/conda/envs/DSX-Python35/lib/python3.5/socket.py in create_connection(address, timeout, source_address)
        711     if err is not None:
    --> 712         raise err
        713     else:

    /opt/conda/envs/DSX-Python35/lib/python3.5/socket.py in create_connection(address, timeout, source_address)
        702                 sock.bind(source_address)
    --> 703             sock.connect(sa)
        704             return sock

    OSError: [Errno 101] Network is unreachable

    During handling of the above exception, another exception occurred:

    URLError                                  Traceback (most recent call last)
    /opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/geopy/geocoders/base.py in _call_geocoder(self, url, timeout, raw, requester, deserializer, **kwargs)
        354         try:
    --> 355             page = requester(req, timeout=timeout, **kwargs)
        356         except Exception as error:

    /opt/conda/envs/DSX-Python35/lib/python3.5/urllib/request.py in open(self, fullurl, data, timeout)
        465 
    --> 466         response = self._open(req, data)
        467 

    /opt/conda/envs/DSX-Python35/lib/python3.5/urllib/request.py in _open(self, req, data)
        483         result = self._call_chain(self.handle_open, protocol, protocol +
    --> 484                                   '_open', req)
        485         if result:

    /opt/conda/envs/DSX-Python35/lib/python3.5/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
        443             func = getattr(handler, meth_name)
    --> 444             result = func(*args)
        445             if result is not None:

    /opt/conda/envs/DSX-Python35/lib/python3.5/urllib/request.py in https_open(self, req)
       1296             return self.do_open(http.client.HTTPSConnection, req,
    -> 1297                 context=self._context, check_hostname=self._check_hostname)
       1298 

    /opt/conda/envs/DSX-Python35/lib/python3.5/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
       1255             except OSError as err: # timeout error
    -> 1256                 raise URLError(err)
       1257             r = h.getresponse()

    URLError: <urlopen error [Errno 101] Network is unreachable>

    During handling of the above exception, another exception occurred:

    GeocoderUnavailable                       Traceback (most recent call last)
    <ipython-input-14-f2b79a21be8c> in <module>()
    ----> 1 affordable['city_coord'] = affordable['Street'].apply(geolocator.geocode).apply(lambda x: (x.latitude, x.longitude))

    /opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
       2508             else:
       2509                 values = self.asobject
    -> 2510                 mapped = lib.map_infer(values, f, convert=convert_dtype)
       2511 
       2512         if len(mapped) and isinstance(mapped[0], Series):

    pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()

    /opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/geopy/geocoders/osm.py in geocode(self, query, exactly_one, timeout, limit, addressdetails, language, geometry, extratags, country_codes, viewbox, bounded)
        385 
        386         return self._parse_json(
    --> 387             self._call_geocoder(url, timeout=timeout), exactly_one
        388         )
        389 

    /opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/geopy/geocoders/base.py in _call_geocoder(self, url, timeout, raw, requester, deserializer, **kwargs)
        378                     raise GeocoderTimedOut('Service timed out')
        379                 elif "unreachable" in message:
    --> 380                     raise GeocoderUnavailable('Service not available')
        381             elif isinstance(error, SocketTimeout):
        382                 raise GeocoderTimedOut('Service timed out')

    GeocoderUnavailable: Service not available

Upvotes: 0

Views: 7371

Answers (1)

user11545193
user11545193

Reputation:

Try to change apply(geolocator.geocode) to apply(nom.geocode)

affordable['city_coord'] = affordable['Street'].apply(nom.geocode).apply(lambda x: (x.latitude, x.longitude))

Upvotes: 2

Related Questions