Django DB Connection with mangoDB using mangoengine gives me error? - django

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.

pip uninstall pymongo
pip install 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

Related

django with celery raise No module named 'kombu' when runserver

I made a website with django and I use celery for asynchronous task, when I run:
./manage.py runserver
I got the error:
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/core/management/base.py", line 341, in run_from_argv
connections.close_all()
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/db/utils.py", line 225, in close_all
for alias in self:
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/db/utils.py", line 219, in __iter__
return iter(self.databases)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/db/utils.py", line 153, in databases
self._databases = settings.DATABASES
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
self._setup(name)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/rouizi/OC_project13/car_rental/__init__.py", line 5, in <module>
from .celery import app as celery_app
File "/home/rouizi/OC_project13/car_rental/celery.py", line 3, in <module>
from celery import Celery
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/celery/local.py", line 509, in __getattr__
module = __import__(self._object_origins[name], None, None, [name])
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/celery/app/__init__.py", line 5, in <module>
from celery import _state
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/celery/_state.py", line 17, in <module>
from celery.utils.threads import LocalStack
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/celery/utils/__init__.py", line 9, in <module>
from kombu.utils.objects import cached_property
ModuleNotFoundError: No module named 'kombu'
I tried to install kombu:
pip install kombu
Collecting kombu
Using cached https://files.pythonhosted.org/packages/34/7e/44445f7d9031e82b4a1160141de35ca810f44041bf5065b45c68ab0ec9e8/kombu-4.6.8-py2.py3-none-any.whl
Requirement already satisfied: amqp<2.6,>=2.5.2 in ./venv/lib/python3.6/site-packages (from kombu)
Requirement already satisfied: importlib-metadata>=0.18; python_version < "3.8" in ./venv/lib/python3.6/site-packages (from kombu)
Requirement already satisfied: vine<5.0.0a1,>=1.1.3 in ./venv/lib/python3.6/site-packages (from amqp<2.6,>=2.5.2->kombu)
Requirement already satisfied: zipp>=0.5 in ./venv/lib/python3.6/site-packages (from importlib-metadata>=0.18; python_version < "3.8"->kombu)
Installing collected packages: kombu
Successfully installed kombu-4.6.8
And now I get this error if a run the server:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/apps/config.py", line 118, in create
cls = getattr(mod, cls_name)
AttributeError: module 'kombu.transport' has no attribute 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/rouizi/OC_project13/venv/lib/python3.6/site-packages/django/apps/config.py", line 136, in create
import_module(entry)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'kombu.transport.django'
I know that the django module was definitely removed from the kombu package but if I remove kombu I get the first error, how can I fix this ?
I am using django==3.0.3, celery==4.4.1, kombu==4.6.8
You use
celery 4.4.1 has requirement kombu<4.7,>=4.6.10, but you'll have kombu 4.6.8 which is incompatible.
Please use:
pip install celery==4.4.6
pip install kombu==4.6.10
and if you want to redis you should this version
pip install redis==3.2.1
Then you to terminal and type python

Django ImportError: No module named 'webapp_credentials'

I am running this code:
https://github.com/cndreisbach/call-for-service/blob/master/docs/src/development.md
When im running this part of code in my Vagrant shell :
python3 ./cfs/manage.py migrate --settings=cfs.settings.local
It's returning me that there is no "ImportError: No module named 'webapp_credentials'"
This is the error :
Traceback (most recent call last):
File "./cfs/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 985, in _gcd_import
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 697, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/vagrant/cfs/cfs/settings/local.py", line 1, in <module>
from .base import *
File "/vagrant/cfs/cfs/settings/base.py", line 15, in <module>
from webapp_credentials import creds
ImportError: No module named 'webapp_credentials'
Is webapp_credentials a module of python OS how do i fix this?
webapp_credentials.py is on .gitignore, that is why migrate can't find it.
You need this file, which is not versioned in this git repository of your link.

Django-cms: 'Settings' object has no attribute 'SITE_ID'

I would like to enable my django-cms instance to host multiple sites.
For that I created two different sites in the admin panel.
Unfortunately only one site is shown because I needed to hardcode the SITE_ID in the project settings.
According to https://github.com/django/django/pull/2460 this is not a mandatory setting anymore. But my Django 1.10.7 instance shows the following traceback if I delete it:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/var/www/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/var/www/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/var/www/venv/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/www/venv/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/var/www/venv/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/var/www/venv/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/var/www/venv/lib/python3.5/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/__init__.py", line 2, in <module>
import cms.admin.pageadmin
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/pageadmin.py", line 39, in <module>
from cms.admin.forms import (
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/forms.py", line 85, in <module>
class PageForm(forms.ModelForm):
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/forms.py", line 86, in PageForm
language = forms.ChoiceField(label=_("Language"), choices=get_language_tuple(),
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/i18n.py", line 76, in get_language_tuple
return [(lang['code'], lang['name']) for lang in get_languages(site_id)]
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/i18n.py", line 23, in get_languages
site_id = get_site_id(site_id)
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py", line 294, in get_site_id
return settings.SITE_ID
File "/var/www/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 49, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'SITE_ID'
Looks like SITE_ID is required by Django CMS, it's in the traceback
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py", line 294, in get_site_id
return settings.SITE_ID
I solved to problem differently.
I used the plugin djangocms-multisite.
I don't know if it is the best solution but it works.

Why import error while using django-templated-email?

I am trying to use BradWhittington Django-Templated-Email. I installed it, and added the following lines in the settings.py.
from templated_email.backends.vanilla_django import TemplateBackend
TEMPLATED_EMAIL_BACKEND = TemplateBackend
When I try to run the server, I get the import error. Even when I use
from templated_email import send_templated_mail
in the models.py I again get the import error. I am new to django, and I googled for the answer many times. But no luck. What am I missing? The 'Run' window on pycharm shows the following:
"C:\Program Files\JetBrains\PyCharm 4.0.4\bin\runnerw.exe" "E:\***\***\***\env1\Scripts\python.exe" "C:\Program Files\JetBrains\PyCharm 4.0.4\helpers\pycharm\django_manage.py" syncdb "E:/***/***/***/***"
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 4.0.4\helpers\pycharm\django_manage.py", line 41, in <module>
run_module(manage_file, None, '__main__', True)
File "C:\Python34\Lib\runpy.py", line 182, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Python34\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Python34\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:/***/***/***/***\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "E:\***\***\***\env1\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "E:\***\***\***\env1\lib\site-packages\django\core\management\__init__.py", line 345, in execute
settings.INSTALLED_APPS
File "E:\***\***\***\env1\lib\site-packages\django\conf\__init__.py", line 46, in __getattr__
self._setup(name)
File "E:\***\***\***\env1\lib\site-packages\django\conf\__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "E:\***\***\***\env1\lib\site-packages\django\conf\__init__.py", line 94, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "E:\***\***\***\env1\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, 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 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "E:/***/***/***/***\***\settings.py", line 17, in <module>
from templated_email.backends.vanilla_django import TemplateBackend
File "E:\***\***\***\env1\lib\site-packages\templated_email\__init__.py", line 23
except ImportError, e:
^
SyntaxError: invalid syntax
Process finished with exit code 1
I am using virtual environment. Please help me.
Django-Templated-Email does not support python 3, which you are using.
You can migrate your project to python2, but it's better to find modern alternative to Django-Templated-Email.

I am getting a following error while using pycharm in windows 8.1

I have started working on python/django. But while using settings.py for database connection, I am getting the following error. I am using pycharm in windows 8.
"C:\Program Files (x86)\JetBrains\PyCharm 4.0.6\bin\runnerw.exe" C:\Python34\python.exe "C:/Users/hp user/PycharmProjects/edu/manage.py" runserver 8000
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 24, in <module>
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/hp user/PycharmProjects/edu/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 312, in execute
django.setup()
File "C:\Python34\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python34\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Python34\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, 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 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "C:\Python34\lib\site-packages\django\contrib\auth\models.py", line 41, in <module>
class Permission(models.Model):
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python34\lib\site-packages\django\db\models\options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Python34\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python34\lib\site-packages\django\db\utils.py", line 240, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python34\lib\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, 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 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
Process finished with exit code 1
Try installing the missing module with:
pip install mysql-python
(you might require sudo).
The author used windows 8 and Python 3.4. mysql-python is not compatible with Python 3.x. Please use mysqlclient
pip install mysqlclient