PerryW
PerryW

Reputation: 1436

Searching LDAP with Python without LDAP library

Here's the problem - I have to work with a blackboxed Linux application server - in other words, I have to work with what I've got, I can't add any libraries.

I have to search an LDAP directory and return user details using Python.

Normally easy... import ldap

Except, I can't, I have no LDAP library to use and can't install one.

Looking for suggestions for a way to do this - there has to something better than shelling out to curl

Upvotes: 3

Views: 928

Answers (1)

PyGuy
PyGuy

Reputation: 551

you can copy the python-ldap installed modules (site-packages/ldap folder) to a directory; then add that directory to the path. then you can import it.

$ cp -R 'site-packages/ldap' 'path-to-local-packages'

>>> import sys
>>> sys.path.append('path-to-local-packages')
>>> import ldap

If it doesn't work; you can also use imp.load_source to dynamically load the module. There are more methods in imp module that you might want to test.

-- Tested

Today I had to perform this myself and it worked OK. I wanted to load a 'python-ldap' library installed in a virtual-env within PythonWin (which does not support venv); I run below commands and it worked:

>>> import sys
>>> sys.path.append(r'C:\Users\PyGuy\.virtualenvs\pyad\Lib\site-packages\python_ldap-2.4.15-py2.7-win32.egg')
>>> import ldap
>>>

Upvotes: 1

Related Questions