doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.86k stars 352 forks source link

Django Project MongoDB Atlas database settings deploy in Azure Web App #614

Open TempleV opened 2 years ago

TempleV commented 2 years ago

I've completed the deployment of the Django project on Azure Web App. However, I am getting errors in DATABASES in settings.py Output:

2022-05-02T06:55:02.451401597Z
2022-05-02T06:55:02.451431497Z   _____
2022-05-02T06:55:02.451436098Z   /  _  \ __________ _________   ____
2022-05-02T06:55:02.451439798Z  /  /_\  \___   /  |  \_  __ \_/ __ \
2022-05-02T06:55:02.451443698Z /    |    \/    /|  |  /|  | \/\  ___/
2022-05-02T06:55:02.451447298Z \____|__  /_____ \____/ |__|    \___  >
2022-05-02T06:55:02.451451298Z         \/      \/                  \/
2022-05-02T06:55:02.451454898Z
2022-05-02T06:55:02.451458298Z A P P   S E R V I C E   O N   L I N U X
2022-05-02T06:55:02.451461898Z
2022-05-02T06:55:02.451465298Z Documentation: http://aka.ms/webapp-linux
2022-05-02T06:55:02.451468898Z Python 3.9.7
2022-05-02T06:55:02.451472298Z Note: Any data outside '/home' is not persisted
2022-05-02T06:55:02.719006413Z Starting OpenBSD Secure Shell server: sshd.
2022-05-02T06:55:02.786525176Z App Command Line not configured, will attempt auto-detect
2022-05-02T06:55:02.786589977Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite
2022-05-02T06:55:02.928485001Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2022-05-02T06:55:02.930243626Z Build Operation ID: |likLu6T3lt8=.9ee5f89a_
2022-05-02T06:55:02.930929635Z Oryx Version: 0.2.20211207.1, Commit: 46633df49cc8fbe9718772a3c894df221273b2af, ReleaseTagName: 20211207.1
2022-05-02T06:55:02.935474200Z Output is compressed. Extracting it...
2022-05-02T06:55:02.936425914Z Extracting '/home/site/wwwroot/output.tar.gz' to directory '/tmp/8da2c056a0fa5da'...
2022-05-02T06:55:08.711058266Z App path is set to '/tmp/8da2c056a0fa5da'
2022-05-02T06:55:08.711440371Z Detected an app based on Django
2022-05-02T06:55:08.711502472Z Generating `gunicorn` command for 'd_project.wsgi'
2022-05-02T06:55:09.089122957Z Writing output script to '/opt/startup/startup.sh'
2022-05-02T06:55:11.072928654Z Using packages from virtual environment antenv located at /tmp/8da2c056a0fa5da/antenv.
2022-05-02T06:55:11.073063656Z Updated PYTHONPATH to ':/opt/startup/code_profiler:/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages'
2022-05-02T06:55:12.205149189Z [2022-05-02 06:55:12 +0000] [36] [INFO] Starting gunicorn 20.1.0
2022-05-02T06:55:12.207164318Z [2022-05-02 06:55:12 +0000] [36] [INFO] Listening at: http://0.0.0.0:8000 (36)
2022-05-02T06:55:12.207482422Z [2022-05-02 06:55:12 +0000] [36] [INFO] Using worker: sync
2022-05-02T06:55:12.226923403Z [2022-05-02 06:55:12 +0000] [37] [INFO] Booting worker with pid: 37
2022-05-02T06:55:19.625885722Z [2022-05-02 06:55:19 +0000] [37] [ERROR] Exception in worker process
2022-05-02T06:55:19.625981524Z Traceback (most recent call last):
2022-05-02T06:55:19.625988624Z   File "/opt/python/3.9.7/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-05-02T06:55:19.626003324Z     worker.init_process()
2022-05-02T06:55:19.626007324Z   File "/opt/python/3.9.7/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
2022-05-02T06:55:19.626011324Z     self.load_wsgi()
2022-05-02T06:55:19.626033425Z   File "/opt/python/3.9.7/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-05-02T06:55:19.626038225Z     self.wsgi = self.app.wsgi()
2022-05-02T06:55:19.626042025Z   File "/opt/python/3.9.7/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-05-02T06:55:19.626045825Z     self.callable = self.load()
2022-05-02T06:55:19.626080325Z   File "/opt/python/3.9.7/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-05-02T06:55:19.626085125Z     return self.load_wsgiapp()
2022-05-02T06:55:19.626088825Z   File "/opt/python/3.9.7/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-05-02T06:55:19.626092725Z     return util.import_app(self.app_uri)
2022-05-02T06:55:19.626096425Z   File "/opt/python/3.9.7/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
2022-05-02T06:55:19.626106726Z     mod = importlib.import_module(module)
2022-05-02T06:55:19.626110526Z   File "/opt/python/3.9.7/lib/python3.9/importlib/__init__.py", line 127, in import_module
2022-05-02T06:55:19.626114326Z     return _bootstrap._gcd_import(name[level:], package, level)
2022-05-02T06:55:19.626118126Z   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2022-05-02T06:55:19.626122326Z   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2022-05-02T06:55:19.626126226Z   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
2022-05-02T06:55:19.626130026Z   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
2022-05-02T06:55:19.626133826Z   File "<frozen importlib._bootstrap_external>", line 850, in exec_module
2022-05-02T06:55:19.626137626Z   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
2022-05-02T06:55:19.626141426Z   File "/tmp/8da2c056a0fa5da/d_project/wsgi.py", line 17, in <module>
2022-05-02T06:55:19.626145326Z     application = get_wsgi_application()
2022-05-02T06:55:19.626149026Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2022-05-02T06:55:19.626152926Z     django.setup(set_prefix=False)
2022-05-02T06:55:19.626156526Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
2022-05-02T06:55:19.626160326Z     apps.populate(settings.INSTALLED_APPS)
2022-05-02T06:55:19.626167626Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/apps/registry.py", line 116, in populate
2022-05-02T06:55:19.626176127Z     app_config.import_models()
2022-05-02T06:55:19.626180027Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/apps/config.py", line 304, in import_models
2022-05-02T06:55:19.626183927Z     self.models_module = import_module(models_module_name)
2022-05-02T06:55:19.626187527Z   File "/opt/python/3.9.7/lib/python3.9/importlib/__init__.py", line 127, in import_module
2022-05-02T06:55:19.626191327Z     return _bootstrap._gcd_import(name[level:], package, level)
2022-05-02T06:55:19.626195427Z   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2022-05-02T06:55:19.626199327Z   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2022-05-02T06:55:19.626203127Z   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
2022-05-02T06:55:19.626206927Z   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
2022-05-02T06:55:19.626210827Z   File "<frozen importlib._bootstrap_external>", line 850, in exec_module
2022-05-02T06:55:19.626214627Z   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
2022-05-02T06:55:19.626218527Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/contrib/auth/models.py", line 3, in <module>
2022-05-02T06:55:19.626222427Z     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
2022-05-02T06:55:19.626226227Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
2022-05-02T06:55:19.626230127Z     class AbstractBaseUser(models.Model):
2022-05-02T06:55:19.626234327Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/db/models/base.py", line 141, in __new__
2022-05-02T06:55:19.626238128Z     new_class.add_to_class("_meta", Options(meta, app_label))
2022-05-02T06:55:19.626241928Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/db/models/base.py", line 369, in add_to_class
2022-05-02T06:55:19.626245828Z     value.contribute_to_class(cls, name)
2022-05-02T06:55:19.626249428Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/db/models/options.py", line 235, in contribute_to_class
2022-05-02T06:55:19.626253328Z     self.db_table, connection.ops.max_name_length()
2022-05-02T06:55:19.626256928Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/utils/connection.py", line 15, in __getattr__
2022-05-02T06:55:19.626260828Z     return getattr(self._connections[self._alias], item)
2022-05-02T06:55:19.626264428Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
2022-05-02T06:55:19.626268628Z     conn = self.create_connection(alias)
2022-05-02T06:55:19.626272328Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/db/utils.py", line 208, in create_connection
2022-05-02T06:55:19.626276128Z     backend = load_backend(db["ENGINE"])
2022-05-02T06:55:19.626282828Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/django/db/utils.py", line 113, in load_backend
2022-05-02T06:55:19.626286728Z     return import_module("%s.base" % backend_name)
2022-05-02T06:55:19.626290528Z   File "/opt/python/3.9.7/lib/python3.9/importlib/__init__.py", line 127, in import_module
2022-05-02T06:55:19.626294428Z     return _bootstrap._gcd_import(name[level:], package, level)
2022-05-02T06:55:19.626298128Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/djongo/base.py", line 12, in <module>
2022-05-02T06:55:19.626302028Z     from .cursor import Cursor
2022-05-02T06:55:19.626305628Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/djongo/cursor.py", line 2, in <module>
2022-05-02T06:55:19.626309629Z     from .sql2mongo.query import Result
2022-05-02T06:55:19.626313229Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/djongo/sql2mongo/__init__.py", line 230, in <module>
2022-05-02T06:55:19.626317229Z     from . import query
2022-05-02T06:55:19.626320929Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/djongo/sql2mongo/query.py", line 35, in <module>
2022-05-02T06:55:19.626324829Z     class CountFunc:
2022-05-02T06:55:19.626328429Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/dataclasses.py", line 958, in dataclass
2022-05-02T06:55:19.626332229Z     return wrap(_cls)
2022-05-02T06:55:19.626335829Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/dataclasses.py", line 950, in wrap
2022-05-02T06:55:19.626339629Z     return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
2022-05-02T06:55:19.626343429Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/dataclasses.py", line 800, in _process_class
2022-05-02T06:55:19.626347229Z     cls_fields = [_get_field(cls, name, type)
2022-05-02T06:55:19.626350929Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/dataclasses.py", line 800, in <listcomp>
2022-05-02T06:55:19.626354829Z     cls_fields = [_get_field(cls, name, type)
2022-05-02T06:55:19.626358429Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/dataclasses.py", line 659, in _get_field
2022-05-02T06:55:19.626362329Z     if (_is_classvar(a_type, typing)
2022-05-02T06:55:19.626365929Z   File "/tmp/8da2c056a0fa5da/antenv/lib/python3.9/site-packages/dataclasses.py", line 550, in _is_classvar
2022-05-02T06:55:19.626369729Z     return type(a_type) is typing._ClassVar
2022-05-02T06:55:19.626373329Z AttributeError: module 'typing' has no attribute '_ClassVar'
2022-05-02T06:55:19.626377530Z [2022-05-02 06:55:19 +0000] [37] [INFO] Worker exiting (pid: 37)
2022-05-02T06:55:19.980153645Z [2022-05-02 06:55:19 +0000] [36] [INFO] Shutting down: Master
2022-05-02T06:55:19.980710553Z [2022-05-02 06:55:19 +0000] [36] [INFO] Reason: Worker failed to boot.

In settings.py

DATABASES = {
        'default': {
            'ENGINE': 'djongo',
            'NAME': 'db-name',
            'CLIENT': {
                'host': 'mongodb+srv://<username>:<password>@<atlas cluster>/<myFirstDatabase>?retryWrites=true&w=majority'
            }  
        }
}

However, Azure is unable to establish a connection with MongoDB Atlas. Is there anybody who knows the proper approach for a Django project to connect to MongoDB Atlas in the Azure web application? How to establish a connection with the MongoDB Atlas in a Django project that has been deployed in Azure Web App. What will the database configurations in settings.py look like?

I need some help. Anyone who can assist me would be much appreciated; I need assistance with this difficulty.