使用mangoengine与mangoDB的Django DB Connection给我错误? [英] Django DB Connection with mangoDB using mangoengine gives me error?

查看:120
本文介绍了使用mangoengine与mangoDB的Django DB Connection给我错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用mongoengine通过django连接mangodb时出现连接错误

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

我已将以下内容添加到设置中.

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

我还创建了名为zaya,用户admin和密码secrete的数据库

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/

错误堆栈跟踪:

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.

推荐答案

似乎您遇到了这个问题: https://github.com/MongoEngine/mongoengine/issues/935 尝试降级到pymongo 2.8

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

这篇关于使用mangoengine与mangoDB的Django DB Connection给我错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆