AmpelAstro/extcats

ServerSelectionTimeoutError

Closed this issue · 2 comments

Running into problem with step 1; connecting to the database. Running the examples in the notebook yields a similar error.

If this build is not yet ready for testing just let me know. I was motivated by the example on the TWiki

python3 
>>> from extcats import CatalogQuery  
>>> test = CatalogQuery.CatalogQuery('milliquas', ra_key = 'ra', dec_key = 'dec')
---------------------------------------------------------------------------
ServerSelectionTimeoutError               Traceback (most recent call last)
<ipython-input-2-054c83d72c9c> in <module>()
----> 1 test = CatalogQuery.CatalogQuery('milliquas', ra_key = 'ra', dec_key = 'dec')

~/Applications/extcats/extcats/CatalogQuery.py in __init__(self, cat_name, ra_key, dec_key, coll_name, dbclient, logger)
     67         if dbclient is None:
     68             self.dbclient = pymongo.MongoClient()
---> 69         self.logger.info("using mongo client at %s:%d"%(self.dbclient.address))
     70 
     71         # find database and collection

/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py in address(self)
    695                                  TOPOLOGY_TYPE.Single):
    696             return None
--> 697         return self._server_property('address')
    698 
    699     @property

/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py in _server_property(self, attr_name)
    661         """
    662         server = self._topology.select_server(
--> 663             writable_server_selector)
    664 
    665         return getattr(server.description, attr_name)

/usr/local/lib/python3.6/site-packages/pymongo/topology.py in select_server(self, selector, server_selection_timeout, address)
    222         return random.choice(self.select_servers(selector,
    223                                                  server_selection_timeout,
--> 224                                                  address))
    225 
    226     def select_server_by_address(self, address,

/usr/local/lib/python3.6/site-packages/pymongo/topology.py in select_servers(self, selector, server_selection_timeout, address)
    181         with self._lock:
    182             server_descriptions = self._select_servers_loop(
--> 183                 selector, server_timeout, address)
    184 
    185             return [self.get_server_by_address(sd.address)

/usr/local/lib/python3.6/site-packages/pymongo/topology.py in _select_servers_loop(self, selector, timeout, address)
    197             if timeout == 0 or now > end_time:
    198                 raise ServerSelectionTimeoutError(
--> 199                     self._error_message(selector))
    200 
    201             self._ensure_opened()

ServerSelectionTimeoutError: localhost:27017: [Errno 61] Connection refused

It turns pymongo will happily try to do its thing even when mongo is not installed.

Following steps solved the issue:

brew install mongo
sudo mkdir -p /data/db
sudo chmod 0755 /data/db

When I start mongo (mongod) before the notebook, I can run the examples.

yes, you need to have mongo installed and the daemon up and running otherwise you'd wait the timeout time (I think 30s by default) just to get the exception.