SSL: CERTIFICATE_VERIFY_FAILED when submitting forms in Django run on Windows VPS with Apache web server

I have a Django website hosted on a VPS (OS Windows server 2019). The web server is Apache 2.4 and Python version is 3.12.8. A Digicert SSL certificate successfully installed and the website is working in production under https. However, I get this error when I try to submit a login or signup form from the website in production:

URLError at /login-page/
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)>

Here is the complete error traceback:

URLError at /login-page/
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)>
Request Method: POST
Request URL:    https://www.mywebsite.com/login-page/
Django Version: 5.0.6
Exception Type: URLError
Exception Value:    <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)>
Exception Location: C:\Python 3.12.8\Lib\urllib\request.py, line 1347, in do_open
Raised during:  users_authentication.views._wrapped_view
Python Executable:  C:\Apache24\bin\httpd.exe
Python Version: 3.12.8
Python Path:    ['C:\\Apache24\\htdocs\\project',
 'C:\\Python 3.12.8\\python312.zip',
 'C:\\Python 3.12.8\\DLLs',
 'C:\\Python 3.12.8\\Lib',
 'C:\\Apache24\\bin',
 'C:\\Python 3.12.8',
 'C:\\Python 3.12.8\\Lib\\site-packages']
C:\Python 3.12.8\Lib\urllib\request.py, line 1344, in do_open
                h.request(req.get_method(), req.selector, req.data, headers,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\http\client.py, line 1336, in request
        self._send_request(method, url, body, headers, encode_chunked)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\http\client.py, line 1382, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\http\client.py, line 1331, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\http\client.py, line 1091, in _send_output
        self.send(msg)
              ^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\http\client.py, line 1035, in send
                self.connect()
                      ^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\http\client.py, line 1477, in connect
            self.sock = self._context.wrap_socket(self.sock,
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\ssl.py, line 455, in wrap_socket
        return self.sslsocket_class._create(
                     …
C:\Python 3.12.8\Lib\ssl.py, line 1041, in _create
                    self.do_handshake()
                          ^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\ssl.py, line 1319, in do_handshake
            self._sslobj.do_handshake()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
During handling of the above exception ([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)), another exception occurred:
C:\Python 3.12.8\Lib\site-packages\django\core\handlers\exception.py, line 55, in inner
                response = get_response(request)
                               ^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\site-packages\django\core\handlers\base.py, line 197, in _get_response
                response = wrapped_callback(request, *callback_args, **callback_kwargs)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Apache24\htdocs\project\users_authentication\views.py, line 48, in _wrapped_view
            return view_func(request, *args, **kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Apache24\htdocs\project\users_authentication\views.py, line 142, in login_vf
        if form.is_valid():
                ^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\site-packages\django\forms\forms.py, line 197, in is_valid
        return self.is_bound and not self.errors
                                          ^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\site-packages\django\forms\forms.py, line 192, in errors
            self.full_clean()
                 ^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\site-packages\django\forms\forms.py, line 327, in full_clean
        self._clean_fields()
             ^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\site-packages\django\forms\forms.py, line 339, in _clean_fields
                    value = field.clean(value)
                                 ^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\site-packages\django\forms\fields.py, line 205, in clean
        self.validate(value)
             ^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\site-packages\django_recaptcha\fields.py, line 69, in validate
            check_captcha = client.submit(
                                 …
C:\Python 3.12.8\Lib\site-packages\django_recaptcha\client.py, line 64, in submit
    response = recaptcha_request(params)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\site-packages\django_recaptcha\client.py, line 39, in recaptcha_request
    return opener.open(
                …
C:\Python 3.12.8\Lib\urllib\request.py, line 515, in open
        response = self._open(req, data)
                        ^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\urllib\request.py, line 532, in _open
        result = self._call_chain(self.handle_open, protocol, protocol +
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\urllib\request.py, line 492, in _call_chain
            result = func(*args)
                          ^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\urllib\request.py, line 1392, in https_open
            return self.do_open(http.client.HTTPSConnection, req,
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ …
C:\Python 3.12.8\Lib\urllib\request.py, line 1347, in do_open
                raise URLError(err)

Below is what my login html page look like:

    <form method="POST">
        {% csrf_token %}
        <fieldset>
          <legend >Login</legend>
            {{form|crispy}}
        </fieldset>
        <div class="form-group mt-5">
             <button type="submit">Login</button>
        </div>
    </form>

Below is the form from the project's app:

class LoginForm(forms.Form):
    email = forms.EmailField()
    password = forms.CharField(widget=forms.PasswordInput)
    captcha = ReCaptchaField(widget=CustomReCaptchaV2Checkbox())

I have unsuccesfuly explored multiple solutions proposed by previous threads with similar error: pip install pip-system-certs pip install certifi python -m pip install pip-system-certs --use-feature=truststore I also set REQUESTS_CA_BUNDLE in the environment variable.

Вернуться на верх