ServerSelectionTimeoutError in Jupyter Notebook

I am getting following error while executing movies.find_one() in Jupyter Notebook. Please share some ideas about what needs to be done:

ServerSelectionTimeoutError Traceback (most recent call last)
1 # find one document in the “movies” collection - does not matter which one
----> 2 movies.find_one()

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\ in find_one(self, filter, *args, **kwargs)
1261 cursor = self.find(filter, *args, **kwargs)
-> 1262 for result in cursor.limit(-1):
1263 return result
1264 return None

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\ in next(self)
1187 if self.__empty:
1188 raise StopIteration
-> 1189 if len(self.__data) or self._refresh():
1190 if self.__manipulate:
1191 _db = self.__collection.database

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\ in _refresh(self)
1086 if not self.__session:
-> 1087 self.__session = self.__collection.database.client._ensure_session()
1089 if self.__id is None: # Query

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\ in _ensure_session(self, session)
1561 # Don’t make implicit sessions causally consistent. Applications
1562 # should always opt-in.
-> 1563 return self.__start_session(True, causal_consistency=False)
1564 except (ConfigurationError, InvalidOperation):
1565 # Sessions not supported, or multiple users authenticated.

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\ in __start_session(self, implicit, **kwargs)
1515 # Raises ConfigurationError if sessions are not supported.
-> 1516 server_session = self._get_server_session()
1517 opts = client_session.SessionOptions(**kwargs)
1518 return client_session.ClientSession(

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\ in _get_server_session(self)
1547 def _get_server_session(self):
1548 “”“Internal: start or resume a _ServerSession.”""
-> 1549 return self._topology.get_server_session()
1551 def _return_server_session(self, server_session, lock):

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\ in get_server_session(self)
430 readable_server_selector,
431 self._settings.server_selection_timeout,
–> 432 None)
434 session_timeout = self._description.logical_session_timeout_minutes

C:\ProgramData\Anaconda3\lib\site-packages\pymongo\ in _select_servers_loop(self, selector, timeout, address)
197 if timeout == 0 or now > end_time:
198 raise ServerSelectionTimeoutError(
–> 199 self._error_message(selector))
201 self._ensure_opened()

ServerSelectionTimeoutError: connection closed,connection closed,connection closed

Please check the URI string in your notebook. Are you able to access the cluster from your system?


Yes, I m getting the stats as well. Please refer to the screenshots for the same.

Please let me know, what needs to be done on priority as my assignment will be due today itself.

Are you able to connect to cluster from command line?

 mongo mongodb+srv://m220student:<PASSWORD>

Please check that you are not connected to VPN or IP should be whitelisted from cluster.


Yes I am able to connect to cluster from command line.
but when I am trying to execute the same command from python terminal, It is giving same error.

Can you share the screenshot and exact commands you are running?
Edit: I am unable to connect to your cluster.


Please find the screen shot as required.

Exact URI is mongodb+srv://

For some reason, I am unable to connect to your cluster. Looking into it.


Can you allow everyone to access the cluster for the testing duration?

Also, are you able to run mflix application after adding this uri in .ini file?

I am getting this status code response for projection but in case of connection it is fine.Will this help in identifying the issue:

Hi @Manish_04653,

To check the error for integration test (from STATUS page), it is always good to check console and code for the same.
Considering the unit tests are passing in each case.

Also, I am unable to replicate the connection issue from my system.


Hi Kanika,
Is there any thing, I can do to resolve this issue.


I’ve been looking into this issue. I’m unable to connect to your cluster to confirm the data is there. Could you please verify the cluster the correct database user and under network access you’ve selected “Allow access from anywhere”?

When drivers connect, they are lazy about it. Until you perform an operation that triggers an action against the database your credentials won’t be verified.

Hi Sir, As you have asked I have performed the same activity but still problem is not solved. data is there as you can see in the below screenshot of cmd.

URI: mongodb+srv://

Please look into it as I am not able to test the test cases at and I have failed in the last two tickets of M220P Class due to it.

Make sure you add your password into your URI string


I just tested this with our fully implemented Mflix application against your cluster after adding the password to the URI. Everything appears to be in order!

Sir, I am also getting the output for the same on the URI but I am not able to fetch the output via Notebook or run the test cases via pytest due to which I can not run test case and dignose anything until I get the exact output which takes a lot of time.

Please find the screen shots for both notebook and pytest:

Pytest Screenshot for Projection which is passed in Status Code page.

I have tried to run the same commands using python terminal but getting same error:

I guess the error is occurring as the data not getting fetched in the specified time as per file and time out is reached. Please let me know what needs to be done from my side to solve the issue.

Hi @Manish_04653,

Please look at this post:

You need to install attr:

 pip install attrs==19.1.0

Let me know if that resolves the issue.


Hi, Kanika,

Thanks a lot. I have successfully completed the course with 91% now.

1 Like