Connecting mongodb atlas through mongoengine in django after hosting on EC2 apache2

171 views
Skip to first unread message

Shubham Kaushik

unread,
May 31, 2021, 2:49:51 AM5/31/21
to MongoEngine Users
Hi Team,

I am trying to host django project on EC2 usnig apache2 which is using mongodb atlas as database.

When I am running this locally on EC2 after openning some port like 8000, it runs properly but on apache it's giving error.

Below is some TLSFeature error, I am facing


###################################################

mod_wsgi (pid=67994, process='tracky', application='ip-IP_ADDRESS|'): Loading Python script file '/home/tracky/tracky-api/tracky/wsgi.py'.

mongodb+srv://username:password@host/dbname?retryWrites=true&w=majority


mod_wsgi (pid=67994): Exception occurred processing WSGI script '/home/tracky/tracky-api/tracky/wsgi.py'.

Traceback (most recent call last):

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/pool.py", line 1278, in _get_socket

    sock_info = self.sockets.popleft()

IndexError: pop from an empty deque


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner

    response = get_response(request)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-  File "/home/tracky/tracky-api/trackyapi/urls.py", line 2, in <module>

    from .views import Tracky

  File "/home/tracky/tracky-api/trackyapi/views.py", line 16, in <module>

    from .serializers import GoalsSerializer, GoalSerializer

  File "/home/tracky/tracky-api/trackyapi/serializers.py", line 9, in <module>

    class GoalSerializer(DocumentSerializer):

  File "/home/tracky/tracky-api/trackyapi/serializers.py", line 11, in GoalSerializer

    uid = ReferenceField(User, write_only=True)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/rest_framework_mongoengine/fields.py", line 217, in __init__

    self.queryset = model.objects

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/mongoengine/queryset/manager.py", line 38, in __get__

    queryset = queryset_class(owner, owner._get_collection())

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/mongoengine/document.py", line 215, in _get_collection

    db = cls._get_db()

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/mongoengine/document.py", line 193, in _get_db

    return get_db(cls._meta.get("db_alias", DEFAULT_CONNECTION_NAME))

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/mongoengine/connection.py", line 363, in get_db

    db.authenticate(

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/database.py", line 1492, in authenticate

    self.client._cache_credentials(

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/mongo_client.py", line 780, in _cache_credentials

    with server.get_socket(all_credentials) as sock_info:

  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__

    return next(self.gen)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/pool.py", line 1231, in get_socket

    sock_info = self._get_socket(all_credentials)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/pool.py", line 1281, in _get_socket

    sock_info = self.connect(all_credentials)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/pool.py", line 1180, in connect

    sock = _configured_socket(self.address, self.opts)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/pool.py", line 1002, in _configured_socket

    sock = ssl_context.wrap_socket(sock, server_hostname=host)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/pyopenssl_context.py", line 313, in wrap_socket

    ssl_conn.do_handshake()

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/pyopenssl_context.py", line 116, in do_handshake

    return self._call(super(_sslConn, self).do_handshake, *args, **kwargs)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/pyopenssl_context.py", line 107, in _call

    return call(*args, **kwargs)

  File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1915, in do_handshake

    self._raise_ssl_error(self._ssl, result)

  File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1618, in _raise_ssl_error

    self._context._ocsp_helper.raise_if_problem()

  File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 294, in raise_if_problem

    raise self._problems.pop(0)

  File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 590, in wrapper

    valid = callback(conn, ocsp_data, data)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/ocsp_support.py", line 292, in _ocsp_callback

    ext = _get_extension(cert, _TLSFeature)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/pymongo/ocsp_support.py", line 119, in _get_extension

    return cert.extensions.get_extension_for_class(klass)

  File "/home/ubuntu/anaconda3/envs/tracky/lib/python3.6/site-packages/cryptography/x509/extensions.py", line 134, in get_extension_for_class

    raise ExtensionNotFound(

cryptography.x509.extensions.ExtensionNotFound: No <class 'cryptography.x509.extensions.TLSFeature'> extension was found

###################################################


Any suggestion will be helpful.


Regards,

Shubham

Reply all
Reply to author
Forward
0 new messages