/ / LDAP (2, 'Keine solche Datei oder ein solches Verzeichnis') bei Verwendung von DJANGO - Python, Django, Django-Models, LDAP, LDAP-Abfrage

LDAP (2, 'Keine solche Datei oder Verzeichnis') Fehler mit DJANGO - Python, Django, Django-Modelle, LDAP, LDAP-Abfrage

Ich implementiere eine Django-App, die ich versucheDaten von einem LDAP-Server abrufen. Hier ist mein Code in views.py.Ich habe alle notwendigen Informationen unten angegeben, aber ich stehe vor einem Fehler (2, "Keine solche Datei oder ein solches Verzeichnis"). Was fehlt mir hier?

                LDAP_USERNAME = ""
LDAP_PASSWORD = ""
LDAP_BASEDN = ""
try:
l = ldap.initialize("")
l.protocol_version = ldap.VERSION2
l.simple_bind_s(LDAP_USERNAME, LDAP_PASSWORD)
search_filter = "(cn=*)"
search_attribute = None
search_scope = ldap.SCOPE_SUBTREE
ldap_result_id = l.search(LDAP_BASEDN, search_scope, search_filter, search_attribute)
result_set = []
while 1:
result_type, result_data = l.result(ldap_result_id, 0)
if (result_data == []):
break
else:
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
print result_set
except ldap.LDAPError, e:
print e

Fehler Traceback:

Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/////views.py", line 43, in index
l = ldap.initialize("xyz")
File "/Library/Python/2.7/site-packages/ldap/functions.py", line 94, in initialize
return LDAPObject(uri,trace_level,trace_file,trace_stack_limit)
File "/Library/Python/2.7/site-packages/ldap/ldapobject.py", line 79, in __init__
self._l = ldap.functions._ldap_function_call(ldap._ldap_module_lock,_ldap.initialize,uri)
File "/Library/Python/2.7/site-packages/ldap/functions.py", line 66, in _ldap_function_call
result = func(*args,**kwargs)
LDAPError: (2, "No such file or directory")

Antworten:

0 für die Antwort № 1

ldap.initialize() erfordert eine korrekte URL für die LDAP-Quelle. Ich hatte ein und dasselbe Problem LDAPError: (0, 'Error') und LDAPError: (2, 'No solche Datei oder Verzeichnis') mit Flasche half mir.

Versuchen ldap.initialize(<protocol>://<host>:<port>). Standard protocol wäre ldap und der Standardport ist 389.