Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-964

Unclear error msg when failing to connect to a Unix Domain Socket

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1
    • Affects Version/s: 3.0.3
    • Component/s: None
    • None

      In pymongo 3.0.x when trying to connect to a unix domain socket without the correct permissions the error message doesn't indicate the reason for failure:

      
      In [1]: from pymongo import MongoClient
      
      In [2]: MongoClient("mongodb:///tmp/mongodb-27017.sock").database_names()
      ---------------------------------------------------------------------------
      ServerSelectionTimeoutError               Traceback (most recent call last)
      <ipython-input-2-857110db2600> in <module>()
      ----> 1 MongoClient("mongodb:///tmp/mongodb-27017.sock").database_names()
      
      /home/vagrant/.virtualenvs/pymongo/local/lib/python2.7/site-packages/pymongo/mongo_client.pyc in database_names(self)
          903                 self.admin.command(
          904                     "listDatabases",
      --> 905                     read_preference=ReadPreference.PRIMARY)["databases"]]
          906
          907     def drop_database(self, name_or_database):
      
      /home/vagrant/.virtualenvs/pymongo/local/lib/python2.7/site-packages/pymongo/database.pyc in command(self, command, value, check, allowable_errors, read_preference, codec_options, **kwargs)
          449         """
          450         client = self.__client
      --> 451         with client._socket_for_reads(read_preference) as (sock_info, slave_ok):
          452             return self._command(sock_info, command, slave_ok, value,
          453                                  check, allowable_errors, read_preference,
      
      /usr/lib/python2.7/contextlib.pyc in __enter__(self)
           15     def __enter__(self):
           16         try:
      ---> 17             return self.gen.next()
           18         except StopIteration:
           19             raise RuntimeError("generator didn't yield")
      
      /home/vagrant/.virtualenvs/pymongo/local/lib/python2.7/site-packages/pymongo/mongo_client.pyc in _socket_for_reads(self, read_preference)
          697         topology = self._get_topology()
          698         single = topology.description.topology_type == TOPOLOGY_TYPE.Single
      --> 699         with self._get_socket(read_preference) as sock_info:
          700             slave_ok = (single and not sock_info.is_mongos) or (
          701                 preference != ReadPreference.PRIMARY)
      
      /usr/lib/python2.7/contextlib.pyc in __enter__(self)
           15     def __enter__(self):
           16         try:
      ---> 17             return self.gen.next()
           18         except StopIteration:
           19             raise RuntimeError("generator didn't yield")
      
      /home/vagrant/.virtualenvs/pymongo/local/lib/python2.7/site-packages/pymongo/mongo_client.pyc in _get_socket(self, selector)
          661     @contextlib.contextmanager
          662     def _get_socket(self, selector):
      --> 663         server = self._get_topology().select_server(selector)
          664         try:
          665             with server.get_socket(self.__all_credentials) as sock_info:
      
      /home/vagrant/.virtualenvs/pymongo/local/lib/python2.7/site-packages/pymongo/topology.pyc in select_server(self, selector, server_selection_timeout, address)
          119         return random.choice(self.select_servers(selector,
          120                                                  server_selection_timeout,
      --> 121                                                  address))
          122
          123     def select_server_by_address(self, address,
      
      /home/vagrant/.virtualenvs/pymongo/local/lib/python2.7/site-packages/pymongo/topology.pyc in select_servers(self, selector, server_selection_timeout, address)
           95                 if server_timeout == 0 or now > end_time:
           96                     raise ServerSelectionTimeoutError(
      ---> 97                         self._error_message(selector))
           98
           99                 self._ensure_opened()
      
      ServerSelectionTimeoutError: %d format: a number is required, not NoneType
      

      In pymongo 2.x I would get a "permission denied" error message, helping me identify the cause of the connection failure.

            Assignee:
            luke.lovett Luke Lovett
            Reporter:
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: