ConnectionError:Socket connection error ssl wrap: [WinError 10054] An existing connection was forcibly closed by the host

from django.shortcuts import render, redirect
from django.contrib import messages
from django.core.management import call_command
from ldap3 import Server, Connection, ALL
from .forms import LDAPConfigForm
from .models import LDAPConfig
def ldap_config_view(request):
    if request.method == 'POST':
        form = LDAPConfigForm(request.POST)
        if form.is_valid():
            server = Server(form.cleaned_data['server'],get_info=ALL)
            connection = Connection(
                server, 
                user=form.cleaned_data['user_dn'], 
                password=form.cleaned_data['password'], 
                authentication="SIMPLE"
            )
            print(connection.result)
            # Test LDAP connection
            # server = Server(config.server, get_info=ALL)
            # connection = Connection(server, user=config.user_dn, password=config.password, authentication="SIMPLE")
            print(connection)
            try:
                if connection.bind():
                    LDAPConfig.objects.all().delete()
                    config = form.save()
                    # Run sync_ldap command
                    call_command('sync_ldap')
                    messages.success(request, 'Connection successful!')

                    return redirect('ldap_config')  
                else:
                    messages.error(request, 'Connection failed!')
            except Exception as e:
                messages.error(request, f'Connection error: {e}')
        else:
            messages.error(request, 'Invalid form data!')
    else:
        form = LDAPConfigForm()
    return render(request, 'ldap_sync/ldap_config_form.html', {'form': form})'

In this code I am trying to connect the LDAP sever to my Django project with ldap3 package while I try to connect to the server I got the Error as ConnectionError:Socket connection error ssl wrap: [WinError 10054] An existing connection was forcibly closed by the host. Actually I am using the Hyper v virtual machine in my local machine to create the AD DS server. I have tried with the OpenLdap server from https://www.forumsys.com/2022/05/10/online-ldap-test-server/ While I try with this site credentials I am able to fetch the users in the Directory when I try to connect the with local windows server with its IP address I got this error I have referred with all the documentations related to Active Directory and I have made all the possible configurations but it does not working. Please guide with this problem

Back to Top