2015-04-12 40 views
0

我使用mongoengine通過django連接mangodb時出現連接錯誤Django數據庫連接與mangoDB使用mangoengine給我錯誤?

我已經包含以下設置。

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

而且我已經分貝名zaya,創建用戶名admin和密碼分泌

爲了創建這個我按照以下鏈接:

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. 

回答

2
pip uninstall pymongo 
pip install pymongo==2.8