Django DB Connection with mangoDB using mangoengine gives me error?

假装没事ソ 提交于 2019-12-25 07:40:05

问题


I am getting the connection error while connecting mangodb through django using mongoengine

I have included following things to settings.

mongoengine.connect('zaya', username='admin', password='secret')
# Mongo DB Sessions
SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'

Also I have created db with name zaya , user admin and password secrete

To create this I have followed below link:

http://petrkout.com/programming/setting-up-django-with-mongodb/

Error Stack Trace:

packages/pymongo/client_options.py", line 108, in <listcomp>
    options = dict([validate(opt, val) for opt, val in iteritems(options)])
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/pymongo/common.py", line 425, in validate
    value = validator(option, value)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/pymongo/common.py", line 249, in validate_read_preference
    raise TypeError("%r is not a read preference." % (value,))
TypeError: False is not a read preference.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
    File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
    File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/core/management/__init__.py", line 338,               
execute_from_command_line
    utility.execute()
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/core/management/__init__.py", line 303, in execute
    settings.INSTALLED_APPS
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/django/conf/__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1448, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/neha/MyProjects/StudentAssessment/src/settings.py", line 103, in <module>
    mongoengine.connect('zaya', username='admin', password='secret')
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/mongoengine/connection.py", line 164, in connect
    return get_connection(alias)
File "/home/neha/MyProjects/StudentAssessment/lib/python3.4/site-packages/mongoengine/connection.py", line 126, in get_connection
    raise ConnectionError("Cannot connect to database %s :\n%s" % (alias, e))
mongoengine.connection.ConnectionError: Cannot connect to database default :
False is not a read preference.

回答1:


It seems you got this issue: https://github.com/MongoEngine/mongoengine/issues/935 Try downgrading to pymongo 2.8

pip uninstall pymongo
pip install pymongo==2.8



回答2:


pip uninstall pymongo
pip install pymongo==2.8


来源:https://stackoverflow.com/questions/29593589/django-db-connection-with-mangodb-using-mangoengine-gives-me-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!