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

problem connecting and query db in pymongo 4.0.1

    • Type: Icon: Question Question
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Used:

      python=3.10.2

      pymongo=4.0.1 (problem)

      pymongo=3.12.0 (works)

      db version v4.2.8

       no tls (dev-setup)

      In [3]: from pymongo import MongoClient
         ...:
         ...: client = MongoClient()
         ...: db = client["mydb"]
         ...: [*db.controlUnit.find()]
      ---------------------------------------------------------------------------
      ServerSelectionTimeoutError               Traceback (most recent call last)
      Input In [3], in <module>
            3 client = MongoClient()
            4 db = client["hpf-larss-data-access"]
      ----> 5 [*db.controlUnit.find()]File C:\Anaconda3\lib\site-packages\pymongo\cursor.py:1159, in Cursor.next(self)
         1157 if self.__empty:
         1158     raise StopIteration
      -> 1159 if len(self.__data) or self._refresh():
         1160     return self.__data.popleft()
         1161 else:File C:\Anaconda3\lib\site-packages\pymongo\cursor.py:1057, in Cursor._refresh(self)
         1054     return len(self.__data)
         1056 if not self.__session:
      -> 1057     self.__session = self.__collection.database.client._ensure_session()
         1059 if self.__id is None:  # Query
         1060     if (self.__min or self.__max) and not self.__hint:File C:\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1603, in MongoClient._ensure_session(self, session)
         1598     return session
         1600 try:
         1601     # Don't make implicit sessions causally consistent. Applications
         1602     # should always opt-in.
      -> 1603     return self.__start_session(True, causal_consistency=False)
         1604 except (ConfigurationError, InvalidOperation):
         1605     # Sessions not supported.
         1606     return NoneFile C:\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1553, in MongoClient.__start_session(self, implicit, **kwargs)
         1551 def __start_session(self, implicit, **kwargs):
         1552     # Raises ConfigurationError if sessions are not supported.
      -> 1553     server_session = self._get_server_session()
         1554     opts = client_session.SessionOptions(**kwargs)
         1555     return client_session.ClientSession(
         1556         self, server_session, opts, implicit)File C:\Anaconda3\lib\site-packages\pymongo\mongo_client.py:1589, in MongoClient._get_server_session(self)
         1587 def _get_server_session(self):
         1588     """Internal: start or resume a _ServerSession."""
      -> 1589     return self._topology.get_server_session()File C:\Anaconda3\lib\site-packages\pymongo\topology.py:530, in Topology.get_server_session(self)
          527 with self._lock:
          528     # Sessions are always supported in load balanced mode.
          529     if not self._settings.load_balanced:
      --> 530         session_timeout = self._check_session_support()
          531     else:
          532         # Sessions never time out in load balanced mode.
          533         session_timeout = float('inf')File C:\Anaconda3\lib\site-packages\pymongo\topology.py:514, in Topology._check_session_support(self)
          509         self._select_servers_loop(
          510             any_server_selector,
          511             self._settings.server_selection_timeout,
          512             None)
          513 elif not self._description.readable_servers:
      --> 514     self._select_servers_loop(
          515         readable_server_selector,
          516         self._settings.server_selection_timeout,
          517         None)
          519 session_timeout = self._description.logical_session_timeout_minutes
          520 if session_timeout is None:File C:\Anaconda3\lib\site-packages\pymongo\topology.py:216, in Topology._select_servers_loop(self, selector, timeout, address)
          213 while not server_descriptions:
          214     # No suitable servers.
          215     if timeout == 0 or now > end_time:
      --> 216         raise ServerSelectionTimeoutError(
          217             "%s, Timeout: %ss, Topology Description: %r" %
          218             (self._error_message(selector), timeout, self.description))
          220     self._ensure_opened()
          221     self._request_check_all()ServerSelectionTimeoutError: mongodb1:27017: [Errno 11001] getaddrinfo failed,mongodb2:27018: [Errno 11001] getaddrinfo failed,mongodb3:27019: [Errno 11001] getaddrinfo failed, Timeout: 30s, Topology Description: <TopologyDescription id: 61f1800055c0a2a6b98c18b6, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('mongodb1', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb1:27017: [Errno 11001] getaddrinfo failed')>, <ServerDescription ('mongodb2', 27018) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb2:27018: [Errno 11001] getaddrinfo failed')>, <ServerDescription ('mongodb3', 27019) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb3:27019: [Errno 11001] getaddrinfo failed')>]>

       

      please let me know, if I can help

       

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            noragen@googlemail.com Tobias Franz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: