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

Posted liangliangzz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

看到一片飘红,有种无力的感觉,其实解决问题很简单,就是要有耐心一个一个去解决,先看一下报的什么错误,去百度一下,尝试自己解决问题,不能动不动就去问别人,问别人有的时候别人还很不耐烦,作为一名程序员,最重要的是解决问题的能力,废话不多说开始解决问题:

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

这个错误说明你的数据库可能没开,打开一下你的数据库就好了。

cd /usr/local/mongoDB/mongodbserver/bin#切换到你的mongodb/bin目录下
输入:
./mongod --dbpath ./

#启动程序

 

是不是很简单?留下你的答案让我们一起学习!

以上是关于pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused的主要内容,如果未能解决你的问题,请参考以下文章