[Solved] Pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

 

/home/mac126/.pyenv/versions/3.6.6/bin/python /home/mac126/Desktop/11/day1/mongo_cache.py
Traceback (most recent call last):
  File "/home/mac126/Desktop/11/day1/mongo_cache.py", line 47, in <module>
    mongo_cache = MongoCache()
  File "/home/mac126/Desktop/11/day1/mongo_cache.py", line 17, in __init__
    self.db.webpage.create_index('timestamp',expireAfterSeconds=expires.total_seconds())
  File "/home/mac126/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pymongo/collection.py", line 1958, in create_index
    self.__create_index(keys, kwargs, session, **cmd_options)
  File "/home/mac126/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pymongo/collection.py", line 1847, in __create_index
    with self._socket_for_writes() as sock_info:
  File "/home/mac126/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pymongo/collection.py", line 196, in _socket_for_writes
    return self.__database.client._socket_for_writes()
  File "/home/mac126/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1085, in _socket_for_writes
    server = self._get_topology().select_server(writable_server_selector)
  File "/home/mac126/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pymongo/topology.py", line 224, in select_server
    address))
  File "/home/mac126/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pymongo/topology.py", line 183, in select_servers
    selector, server_timeout, address)
  File "/home/mac126/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

Process finished with exit code 1

When you see a piece of red, you feel powerless. In fact, it’s very easy to solve problems one by one. You need to be patient to solve them one by one. First, you need to see what mistakes are reported, go to Baidu and try to solve problems by yourself. You can’t always ask others. Sometimes others are impatient. As a programmer, the most important thing is the ability to solve problems, Stop talking nonsense and start solving problems:

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

This error indicates that your database may not be open. Just open your database

cd /usr/local/mongoDB/mongodbserver/bin#Switch to your mongodb/bin directory
Enter.
. /mongod --dbpath . /

# Start the program

Similar Posts: