简体   繁体   English

使用Python搜索LDAP而不使用LDAP库

[英]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. 这是问题 - 我必须使用黑盒子Linux应用程序服务器 - 换句话说,我必须使用我已经拥有的东西,我不能添加任何库。

I have to search an LDAP directory and return user details using Python. 我必须搜索LDAP目录并使用Python返回用户详细信息。

Normally easy... import ldap 通常很容易...导入ldap

Except, I can't, I have no LDAP library to use and can't install one. 除了,我不能,我没有使用LDAP库,也无法安装。

Looking for suggestions for a way to do this - there has to something better than shelling out to curl 正在寻找一种方法来做到这一点 - 有一些东西比外壳更好地卷曲

you can copy the python-ldap installed modules (site-packages/ldap folder) to a directory; 你可以将python-ldap安装的模块(site-packages / ldap文件夹)复制到一个目录中; 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. 您还可以使用imp.load_source动态加载模块。 There are more methods in imp module that you might want to test. 您可能希望测试imp模块中有更多方法。

-- 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); 我想在PythonWin中加载一个安装在virtual-env中的'python-ldap'库(它不支持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
>>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM