Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching LDAP with Python without LDAP library

Tags:

python

ldap

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

like image 888
PerryW Avatar asked Jan 24 '26 07:01

PerryW


1 Answers

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
>>>
like image 91
PyGuy Avatar answered Jan 25 '26 21:01

PyGuy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!