PyOne icon indicating copy to clipboard operation
PyOne copied to clipboard

ServerSelectionTimeoutError: localhost:27017: [Errno 111] ECONNREFUSED

Open Face-Smile opened this issue 6 years ago • 0 comments

[2019-08-24 23:39:02,029] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/flask_limiter/extension.py", line 544, in __inner
    return obj(*a, **k)
  File "/home/xiaoxiaoguai/pyone/app/front/views.py", line 78, in index
    password,_,cur=has_item(path,'.password')
  File "/home/xiaoxiaoguai/pyone/app/utils/common.py", line 322, in has_item
    if mon_db.items.count()==0:
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/pymongo/collection.py", line 1800, in count
    return self._count(cmd, collation, session)
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/pymongo/collection.py", line 1600, in _count
    _cmd, self._read_preference_for(session), session)
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 1455, in _retryable_read
    read_pref, session, address=address)
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 1254, in _select_server
    server = topology.select_server(server_selector)
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/pymongo/topology.py", line 231, in select_server
    address))
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/pymongo/topology.py", line 189, in select_servers
    selector, server_timeout, address)
  File "/home/xiaoxiaoguai/pyone/venv/local/lib/python2.7/site-packages/pymongo/topology.py", line 205, in _select_servers_loop
    self._error_message(selector))
ServerSelectionTimeoutError: localhost:27017: [Errno 111] ECONNREFUSED

一直报这个错,MongoDB没有设置密码,MongoDB 4.2,MongoDB3.6 试了都一样

单独测试python2连接MongoDB没有问题

Python 2.7.15+ (default, Nov 27 2018, 23:36:35)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> client=pymongo.MongoClient(host='localhost', port=27017)
>>> client.database_names()
[u'admin', u'config', u'local']
>>> client.get_database('test')
Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), u'test')

Face-Smile avatar Aug 25 '19 01:08 Face-Smile