0
votes

I am trying to extend an existing LDAP database to allow the users to register WLAN devices. For this I would like to utilize the Django framework. A promising looking plugin is django-ldapdb which I would like to try out.

Main problem

The issue is with getting this plugin to run on my Windows 10 machine. I am using Python 3.6.1 and would like to develop in JetBrain's PyCharm.
Installing the plugin through pip install django-ldapdb results in an error (ellipses indicating left out log):

(...)
running build_ext
building '_ldap' extension
creating build\temp.win32-3.6
creating build\temp.win32-3.6\Release
creating build\temp.win32-3.6\Release\Modules
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=2.4.28 -IModules -I/usr/include -I/usr/include/sasl -I/usr/local/include -I/usr/local/include/sasl "-Ic:\program files (x86)\python36-32\include" "-Ic:\program files (x86)\python36-32\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt" /TcModules/LDAPObject.c /Fobuild\temp.win32-3.6\Release\Modules/LDAPObject.obj
LDAPObject.c
c:\users\j0hj0h\appdata\local\temp\pip-build-j0vdz6mm\pyldap\modules\errors.h(8): fatal error C1083: Cannot open include file: 'lber.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2

----------------------------------------
Command ""c:\program files (x86)\python36-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\j0hj0h\\AppData\\Local\\Temp\\pip-build-j0vdz6mm\\pyldap\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\j0hj0h\AppData\Local\Temp\pip-n_a_dcd5-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\j0hj0h\AppData\Local\Temp\pip-build-j0vdz6mm\pyldap\

The plugin's page mentions dependencies to LDAP packages. Since I use Windows, I do not know how to install those.

Further investigation

After a tough search and much experimentation, I found a way to produce a different error, which I think is a smaller issue.

I tried installing the Python LDAP package (pip install python-ldap), yielding a syntax error:

Collecting python-ldap
  Using cached python-ldap-2.4.32.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\J0hj0h\AppData\Local\Temp\pip-build-snzefz4h\python-ldap\setup.py", line 53
        print name + ': ' + cfg.get('_ldap', name)
                 ^
    SyntaxError: invalid syntax

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in  C:\Users\J0hj0h\AppData\Local\Temp\pip-build-snzefz4h\python-ldap\

Trying to install an alternative package (pip install pyldap) results in the same error as the attempt of installing django-ldapdb:

    (...)
    running build_ext
    building '_ldap' extension
    creating build\temp.win32-3.6
    creating build\temp.win32-3.6\Release
    creating build\temp.win32-3.6\Release\Modules
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=2.4.28 -IModules -I/usr/include -I/usr/include/sasl -I/usr/local/include -I/usr/local/include/sasl "-Ic:\program files (x86)\python36-32\include" "-Ic:\program files (x86)\python36-32\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt" /TcModules/LDAPObject.c /Fobuild\temp.win32-3.6\Release\Modules/LDAPObject.obj
    LDAPObject.c
    c:\users\j0hj0h\appdata\local\temp\pip-build-rr10feu9\pyldap\modules\errors.h(8): fatal error C1083: Cannot open include file: 'lber.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2

    ----------------------------------------
Command ""c:\program files (x86)\python36-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\J0hj0h\\AppData\\Local\\Temp\\pip-build-rr10feu9\\pyldap\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\J0hj0h\AppData\Local\Temp\pip-4vbw823_-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\J0hj0h\AppData\Local\Temp\pip-build-rr10feu9\pyldap\

I do not know much about it, but read that one can install the packages as wheels from some site. Both wheels for python-ldap fail with an error:

python_ldap-2.4.32-cp27-cp27m-win_amd64.whl is not a supported wheel on this platform.

Almost the same goes for the wheels for pyldap. I tried the three latest versions (pyldap‑2.4.28‑cp35‑cp35m‑win_amd64.whl, pyldap‑2.4.28‑cp36‑cp36m‑win32.whl, pyldap‑2.4.28‑cp36‑cp36m‑win_amd64.whl) and of those only the 32-bit version (pyldap‑2.4.28‑cp36‑cp36m‑win_amd64.whl) was successfully installed.

Then I am able to install the Django plugin (pip install django-ldapdb). In the Django project, I started an app called ldap and modified settings.py according to the plugin's docs:

DATABASES = {
    'ldap': {
        'ENGINE': 'ldapdb.backends.ldap',
        'NAME': 'ldap://localhost',
        'USER': 'cn=admin,dc=example,dc=org',
        'PASSWORD': 'admin',
    },
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
DATABASE_ROUTERS = ['ldapdb.router.Router']

If I know run the project with PyCharm, the error changes to the module ldap.filter missing:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03A1DBB8>
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\management\base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\checks\model_checks.py", line 30, in check_all_models
    errors.extend(model.check(**kwargs))
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\models\base.py", line 1282, in check
    errors.extend(cls._check_fields(**kwargs))
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\models\base.py", line 1357, in _check_fields
    errors.extend(field.check(**kwargs))
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\models\fields\__init__.py", line 909, in check
    errors = super(AutoField, self).check(**kwargs)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\models\fields\__init__.py", line 219, in check
    errors.extend(self._check_backend_specific_checks(**kwargs))
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\models\fields\__init__.py", line 321, in _check_backend_specific_checks
    if router.allow_migrate(db, app_label, model_name=self.model._meta.model_name):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\utils.py", line 293, in allow_migrate
    for router in self.routers:
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\utils.py", line 251, in routers
    router = import_string(r)()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\utils\module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "C:\Program Files (x86)\Python36-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\ldapdb\__init__.py", line 8, in <module>
    import ldap.filter
ModuleNotFoundError: No module named 'ldap.filter'

Installing OpenLDAP for Windows did not resolve the issue.

Suggestions?

I am going a bit crazy since I have no idea how to fix this issue and what might cause it. Do you have any idea what the cause is and how to get django-ldapdb working on Windows?

2
You can try to install OpenLDAP on Windows, here is installer: sourceforge.net/projects/openldapwindows.illagrenan
Thanks for your comment. I tried another download from userbooster.de/download/openldap-for-windows.aspx, but it did not resolve the issue. Thanks anyway! :)J0hj0h
Could you start the python shell and try import ldap and import ldap.filter?ikreb

2 Answers

0
votes

The libraries are not available for Windows. However, using Docker it is possible to run a Debian container and install them. The missing libraries are:

libldap2-dev
libsasl2-dev

Installing those enables the installation of django-ldapdb.

0
votes

If you want to use Python3, you have to install pyldap. python-ldap doesn't support Python3.

So at first, download pyldap‑2.4.37‑cp36‑cp36m‑win32.whl and install it with the command

pip install pyldap‑2.4.37‑cp36‑cp36m‑win32.whl

And then you can also install django-ldapdb:

pip install django-ldapdb