我们已经安装了python-ldap(2.4.19)模块而没有错误,并成功执行了大部分操作.但是,当我们尝试加载证书以使用ssl(ldaps)时,ldap.set_option总是返回异常.
它出现在运行Yosemite的笔记本电脑上,但不会出现在Mavericks或Linux上.(所有Macbook都安装了xcode)
我们认为它应该是一些缺失/过时/更新的lib,但我们不知道如何找到它.
有线索吗?
$python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
...
>>>import ldap
>>>ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, '/my_path/my_cert.crt')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/*xxx*/python2.7/site-packages/ldap/functions.py", line 133, in set_option
return _ldap_function_call(None,_ldap.set_option,option,invalue)
File "/*xxx*/python2.7/site-packages/ldap/functions.py", line 64, in _ldap_function_call
result = func(*args,**kwargs)
ValueError: option error
Run Code Online (Sandbox Code Playgroud) 我一直在尝试在MacOS X 10.9.5和Python 2.7.9下使用Python-LDAP(版本2.4.19)
我想在调用之后验证我与给定LDAP服务器的连接.start_tls_s()(或者如果无法验证证书则使方法引发和异常).(我也想检查CRL,但这是另一回事).
这是我的代码:
#!python
#!/usr/bin/env python
import ConfigParser, os, sys
import ldap
CACERTFILE='./ca_ldap.bad'
## CACERTFILE='./ca_ldap.crt'
config = ConfigParser.ConfigParser()
config.read(os.path.expanduser('~/.ssh/creds.ini'))
uid = config.get('LDAP', 'uid')
pwd = config.get('LDAP', 'pwd')
svr = config.get('LDAP', 'svr')
bdn = config.get('LDAP', 'bdn')
ld = ldap.initialize(svr)
ld.protocol_version=ldap.VERSION3
ld.set_option(ldap.OPT_DEBUG_LEVEL, 255 )
ld.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
ld.set_option(ldap.OPT_X_TLS_CACERTFILE, CACERTFILE)
ld.set_option(ldap.OPT_X_TLS_DEMAND, True )
ld.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_HARD)
## From: https://stackoverflow.com/a/7810308/149076
## and : http://python-ldap.cvs.sourceforge.net/viewvc/python-ldap/python-ldap/Demo/initialize.py?revision=1.14&view=markup
ld.start_tls_s()
for each in dir(ldap):
if 'OPT_X_TLS' in each:
try:
print '\t*** %s: %s' % …Run Code Online (Sandbox Code Playgroud) 试图为我的Django项目安装python-ldap - 到目前为止尝试了easy_install,pip,以及构建自己,但仍然得到相同的错误:
dlopen(/Library/Python/2.6/site-packages/_ldap.so, 2): Symbol not found: _ldap_create_assertion_control_value
Referenced from: /Library/Python/2.6/site-packages/_ldap.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/_ldap.so
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
我正在尝试使用 pip 安装 python-ldap 包。执行时出现以下错误pip install python-ldap。我尝试根据此问题安装与 ubuntu 17.10 ( Artful ) 对应的软件包,但还没有运气。我错过了什么包裹?
上述堆栈溢出问题中的解决方案是安装
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
但在 17.10 中我看不到libsasl2-dev&libldap2-dev而是我可以看到包libsasl-2-2& libldap-2.4-2。我和phthon-dev&一起安装了它们libssl-dev。但我仍然收到以下错误。似乎我缺少一些包含 lber.h 文件的软件包安装。
我得到的错误:
In file included from Modules/LDAPObject.c:8:0:
Modules/constants.h:7:10: fatal error: lber.h: No such file or directory
#include "lber.h"
^~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
Python 版本 - 3.6.3
点子版本 - 19.1.1
我在 Ubuntu 20.04 上的 Python 虚拟环境中安装 Odoo 15。我已经从官方 GitHub 存储库下载了 Odoo,并使用 Nginx 作为反向代理。
\n按照文档在 ubuntu 22.04 中安装和设置 odoo 后,我确实遵循了此链接中的操作文档
\n当我使用命令安装 pip 软件包时,我收到此错误\n pip install -r requirement.txt\nany help please。
Building wheels for collected packages: python-ldap\n Building wheel for python-ldap (pyproject.toml) ... error\n error: subprocess-exited-with-error\n \n \xc3\x97 Building wheel for python-ldap (pyproject.toml) did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [111 lines of output]\n /tmp/pip-build-env-rbfhnio_/overlay/lib/python3.10/site-packages/setuptools/config/setupcfg.py:516: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.\n warnings.warn(msg, warning_class)\n …Run Code Online (Sandbox Code Playgroud) 有没有办法在python-LDAP中手动设置"simple_bind_s"的超时?我测试了ldapObject.timeout = 10它对我不起作用.有任何想法吗?
提前致谢..
似乎Heroku不支持python-ldap.在requirements.txt文件中使用"python-ldap == 2.3.13"的pip安装失败,并在Heroku中出现以下错误:
GCC -pthread -fno严格走样-g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict的原型-fPIC -DHAVE_LIBLDAP_R -DHAVE_SASL -DHAVE_TLS -DLDAPMODULE_VERSION = 2.3.13 -IModules -I/USR /本地/ OpenLDAP的-2.3 /包括-I/USR /包含/ SASL -I/USR /本地/包含/ python2.7 -c模块/ LDAPObject.c -o建立/ temp.linux-x86_64-2.7 /模块/ LDAPObject.o
Modules/LDAPObject.c:18:18:错误:sasl.h:没有这样的文件或目录
看起来Heroku没有python-ldap所需的库,我不知道是否有办法安装依赖库,除了'pip'.
在Heroku的Python/Django堆栈中支持ldap认证的推荐解决方案是什么?
非常感谢您的帮助.
我使用LDAP模块的蟒蛇连接到LDAP服务器.我能够查询数据库,但我不知道如何检索数据库中存在的字段,以便我可以提前通知用户查询数据库,告诉他他试图访问的字段不在数据库中.
例如,如果存在的字段是公正的
cn
memberOf
Run Code Online (Sandbox Code Playgroud)
如果用户尝试使用过滤器查询数据库
cn and memberOf and notcontained
Run Code Online (Sandbox Code Playgroud)
我应该能够知道notbtained属性不在dabase模式中.
我怎样才能做到这一点.
谢谢.
您能否建议以下故障排除方法;我试图绑定到ldap服务器,但是徒劳无功,
openssl s_client -CApath /etc/pki/ca-trust/source/anchors/ -connect ...:636
Run Code Online (Sandbox Code Playgroud)
成功:
Verify return code: 0 (ok)
Run Code Online (Sandbox Code Playgroud)
那是从系统方面来看的,但是当我尝试通过python-ldap模块进行绑定时:
In [1]: import ldap
In [2]: l = ldap.initialize('ldaps://...:636')
In [3]: ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_ALLOW)
In [4]: l.set_option(ldap.OPT_X_TLS_CACERTFILE,"/etc/pki/ca-trust/source/anchors/cacert.pem")
In [5]: l.set_option(ldap.OPT_X_TLS_NEWCTX,0)
In [6]: l.simple_bind_s("...", "...")
---------------------------------------------------------------------------
SERVER_DOWN Traceback (most recent call last)
<ipython-input-6-a59dae8ba541> in <module>()
----> 1 l.simple_bind_s("...", "...")
/usr/lib64/python2.7/site-packages/ldap/ldapobject.pyc in simple_bind_s(self, who, cred, serverctrls, clientctrls)
205 simple_bind_s([who='' [,cred='']]) -> None
206 """
--> 207 msgid = self.simple_bind(who,cred,serverctrls,clientctrls)
208 resp_type, resp_data, resp_msgid, resp_ctrls = self.result3(msgid,all=1,timeout=self.timeout)
209 return resp_type, resp_data, …Run Code Online (Sandbox Code Playgroud) 我能够通过python-ldap绑定和查询Active Directory,除了在AD上添加或修改属性之外没有任何问题.我可以添加属性,但编码似乎已关闭,因为所有文本都是乱码.
我尝试用utf8编码我的字符串和其他几个没有运气的字符串.
我还尝试使用域管理员帐户绑定以及绑定到我将更改属性的用户帐户,无论如何都是相同的结果.
这是我用来更新属性的方法:
LdapHelpers类:
def __init__(self):
import ldap
# set globals
self.server = 'LDAP://dc.mycompany.com'
self.admin_dn = 'CN=Administrator,CN=users,DC=mycompany,DC=com'
self.admin_pass = 'coolpassword'
# init LDAP connection
#ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, 0)
ldap.set_option(ldap.OPT_REFERRALS, 0)
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
ldap.protocol_version = ldap.VERSION3
self.ldap = ldap.initialize(self.server)
def update_attribute(self, attrib, value):
try:
import ldap
conn = self.ldap
conn.simple_bind_s(self.admin_dn, self.admin_pass)
mod_attrs = [( ldap.MOD_REPLACE, "mobile", "6306564123")]
# I have tried other variations of the above
# mod_attrs = [( ldap.MOD_REPLACE, "mobile", "6306564123".encode('utf-8)]
conn.modify_s('CN=Mike Smith,OU=GoogleApps,DC=company,DC=com', mod_attrs)
print 'record updated'
except ldap.LDAPError …Run Code Online (Sandbox Code Playgroud) python-ldap ×10
python ×8
ldap ×3
ssl ×2
ca ×1
certificate ×1
django ×1
heroku ×1
odoo ×1
openssl ×1
osx-yosemite ×1
pip ×1
python-2.7 ×1
python-3.6 ×1
python-venv ×1
timeout ×1
ubuntu-17.10 ×1