Connection error during pymongo in jupyter to locla mongodb server

i have been trying to connect and work using python. But when i try listing databases it throws an error.

here is the code

# Importing the required libraries
import pymongo
# Connect to local MongoDB server
client = pymongo.MongoClient('mongodb://localhost:27017/')
# Client

after this i get an error

ServerSelectionTimeoutError               Traceback (most recent call last)
<ipython-input-6-62f658703d98> in <module>
----> 1 client.list_database_names()

~/.local/lib/python3.6/site-packages/pymongo/ in list_database_names(self, session, comment)
   1784         .. versionadded:: 3.6
   1785         """
-> 1786         return [doc["name"] for doc in self.list_databases(session, nameOnly=True, comment=comment)]
   1788     def drop_database(

~/.local/lib/python3.6/site-packages/pymongo/ in list_databases(self, session, comment, **kwargs)
   1757             cmd["comment"] = comment
   1758         admin = self._database_default_options("admin")
-> 1759         res = admin._retryable_read_command(cmd, session=session)
   1760         # listDatabases doesn't return a cursor (yet). Fake one.
   1761         cursor = {

~/.local/lib/python3.6/site-packages/pymongo/ in _retryable_read_command(self, command, value, check, allowable_errors, read_preference, codec_options, session, **kwargs)
    763             )
--> 765         return self.__client._retryable_read(_cmd, read_preference, session)
    767     def _list_collections(self, sock_info, session, read_preference, **kwargs):

~/.local/lib/python3.6/site-packages/pymongo/ in _retryable_read(self, func, read_pref, session, address, retryable)
   1362         while True:
   1363             try:
-> 1364                 server = self._select_server(read_pref, session, address=address)
   1365                 with self._socket_from_server(read_pref, server, session) as (sock_info, read_pref):
   1366                     if retrying and not retryable:

~/.local/lib/python3.6/site-packages/pymongo/ in _select_server(self, server_selector, session, address)
   1194                     raise AutoReconnect("server %s:%d no longer available" % address)
   1195             else:
-> 1196                 server = topology.select_server(server_selector)
   1197             return server
   1198         except PyMongoError as exc:

~/.local/lib/python3.6/site-packages/pymongo/ in select_server(self, selector, server_selection_timeout, address)
    249     def select_server(self, selector, server_selection_timeout=None, address=None):
    250         """Like select_servers, but choose a random server if several match."""
--> 251         servers = self.select_servers(selector, server_selection_timeout, address)
    252         if len(servers) == 1:
    253             return servers[0]

~/.local/lib/python3.6/site-packages/pymongo/ in select_servers(self, selector, server_selection_timeout, address)
    211         with self._lock:
--> 212             server_descriptions = self._select_servers_loop(selector, server_timeout, address)
    214             return [self.get_server_by_address(sd.address) for sd in server_descriptions]

~/.local/lib/python3.6/site-packages/pymongo/ in _select_servers_loop(self, selector, timeout, address)
    227                 raise ServerSelectionTimeoutError(
    228                     "%s, Timeout: %ss, Topology Description: %r"
--> 229                     % (self._error_message(selector), timeout, self.description)
    230                 )

ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 64cb7b71341a70310f04d71c, topology_type: Unknown, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused',)>]>

Either your mongod configuration has errors or your request URI is not in compliance with the current configuration. Please consult with regard to your configuration.

thanks for the response.Can you specify which configuration setting to look for. I’m a beginner and dont have much experience

  • Check which interfaces you have enabled.
  • Check whether you have authentication enabled.

the authentication is disabled and interfaces enabled are set to:

It sounds like perhaps the MongoDB server mongod is not actually running?