我遇到了將mongoengine加入我的django應用程序的問題。下面是我得到的錯誤:mongoengine.connection.ConnectionError:無法連接到數據庫默認值:[Errno 111]連接被拒絕
Traceback (most recent call last):
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 374, in __init__
self._ensure_connected(True)
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 939, in _ensure_connected
self.__ensure_member()
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 813, in __ensure_member
member, nodes = self.__find_node()
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 904, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/dk2459/.local/lib/python3.4/site-packages/mongoengine/connection.py", line 133, in get_connection
_connections[alias] = connection if connection else connection_class(**conn_settings)
File "/home/dk2459/.local/lib/python3.4/site-packages/pymongo/mongo_client.py", line 377, in __init__
raise ConnectionFailure(str(e))
pymongo.errors.ConnectionFailure: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "create_admin.py", line 7, in <module>
connect('happy_lens')
File "/home/dk2459/.local/lib/python3.4/site-packages/mongoengine/connection.py", line 173, in connect
return get_connection(alias)
File "/home/dk2459/.local/lib/python3.4/site-packages/mongoengine/connection.py", line 135, in get_connection
raise ConnectionError("Cannot connect to database %s :\n%s" % (alias, e))
mongoengine.connection.ConnectionError: Cannot connect to database default :
[Errno 111] Connection refused
下面是我試圖運行代碼:
import getpass
from mongoengine import connect
from models import User
connect('happy_lens')
admin = User(username='dk', email='[email protected]')
admin.password='pwd'
admin.save()
及以下相關的settings.py代碼:
DATABASES = {
'default' : {
'ENGINE': 'django_mongodb_engine',
'NAME': 'happy_lens',
'HOST': '192.168.1.35',
'POST': 12345
}
}
SESSION_ENGINE = 'mongoengine.django.sessions'
一切我搜索沒有工作。請幫忙。
在/ var/lib中/ MongoDB的拆卸mongod.lock並重新啓動服務或可能(如果你沒有),你可以嘗試從這裏的解決方案http://stackoverflow.com/questions/24899849/connection-refused-to-mongodb-errno-111 –
我查找/ var/lib中的mongodb文件夾/並找不到它。你知道什麼可能導致這個問題?我已經通過pip3安裝 - 用戶mongoengine安裝了mongonenine。 – no8do