2

运行 python3.6
ldap3-python 库
在 docker 容器上使用 OpenLDAP osixia/docker-openldap
端口 389 和 636 已打开。我可以从 python 的控制台中看到连接;但是,我遇到了问题。
在主机上的 jupyter 笔记本上运行 python

我似乎无法让 conn.bind() 工作。这是我的代码:

from ldap3 import Connection, Server, ALL
 server = Server('127.0.0.1')
 conn = Connection(server, user='cn=admin,dc=example,dc=org', 
 password="admin")
 conn.open()
 conn.bind()

这是错误:

>-------------------------------------------------------------------------->-
>TypeError                                 Traceback (most recent call last)
><ipython-input-3-5c5644694a2b> in <module>()
      2 conn = Connection(server, user='cn=admin,dc=example,dc=org', password="admin")
      3 conn.open()
----> 4 conn.bind()

>~/anaconda3/lib/python3.6/site-packages/ldap3/core/connection.py in bind(self, read_server_info, controls)
    425                     if log_enabled(PROTOCOL):
    426                         log(PROTOCOL, 'simple BIND request <%s> sent via <%s>', bind_request_to_dict(request), self)
--> 427                     response = self.post_send_single_response(self.send('bindRequest', request, controls))
    428                 elif self.authentication == SASL:
    429                     if self.sasl_mechanism in SASL_AVAILABLE_MECHANISMS:

>~/anaconda3/lib/python3.6/site-packages/ldap3/strategy/sync.py in post_send_single_response(self, message_id)
    120         Returns the result message or None
    121         """
--> 122         responses, result = self.get_response(message_id)
    123         self.connection.result = result
    124         if result['type'] == 'intermediateResponse':  # checks that all responses are intermediates (there should be only one)

>~/anaconda3/lib/python3.6/site-packages/ldap3/strategy/base.py in get_response(self, message_id, timeout)
    296         if self._outstanding and message_id in self._outstanding:
    297             while timeout >= 0:  # waiting for completed message to appear in responses
--> 298                 responses = self._get_response(message_id)
    299                 if not responses:
    300                     sleep(RESPONSE_SLEEPTIME)

>~/anaconda3/lib/python3.6/site-packages/ldap3/strategy/sync.py in _get_response(self, message_id)
    166                             log(EXTENDED, 'ldap message received via <%s>:%s', self.connection, format_ldap_message(ldap_resp, '<<'))
    167                         if int(ldap_resp['messageID']) == message_id:
--> 168                             dict_response = self.decode_response(ldap_resp)
    169                             ldap_responses.append(dict_response)
    170                             if dict_response['type'] not in ['searchResEntry', 'searchResRef', 'intermediateResponse']:

>~/anaconda3/lib/python3.6/site-packages/ldap3/strategy/base.py in decode_response(self, ldap_message)
    401         if message_type == 'bindResponse':
    402             if not bytes(component['matchedDN']).startswith(b'NTLM'):  # patch for microsoft ntlm authentication
--> 403                 result = bind_response_to_dict(component)
    404             else:
    405                 result = sicily_bind_response_to_dict(component)

>~/anaconda3/lib/python3.6/site-packages/ldap3/operation/bind.py in bind_response_to_dict(response)
    117             'message': str(response['diagnosticMessage']),
    118             'referrals': referrals_to_list(response['referral']),
--> 119             'saslCreds': bytes(response['serverSaslCreds']) if response['serverSaslCreds'] is not None else None}
    120 
    121 

>~/anaconda3/lib/python3.6/site-packages/pyasn1/type/univ.py in __bytes__(self)
    888 
    889         def __bytes__(self):
--> 890             return bytes(self._value)
    891 
    892         def asOctets(self):

>TypeError: cannot convert 'NoValue' object to bytes

我看到我的 ldap 服务器上发生了连接:

ldap_1 | 5a794f6d conn=1045 fd=15 接受来自 IP=172.20.0.1:42060 (IP=0.0.0.0:389) ldap_1 | 5a794f6d conn=1045 op=0 BIND dn="cn=admin,dc=example,dc=org" 方法=128 ldap_1 | 5a794f6d conn=1045 op=0 BIND dn="cn=admin,dc=example,dc=org" mech=SIMPLE ssf=0
ldap_1 | 5a794f6d conn=1045 op=0 结果标签=97 err=0 文本=

当我进行本地连接时,我会返回结果,这就是我在服务器上看到的:

ldap_1 | 5a795085 conn=1046 fd=16 接受来自 IP=127.0.0.1:48488 (IP=0.0.0.0:389)
ldap_1 | 5a795085 conn=1046 op=0 BIND dn="cn=admin,dc=example,dc=org" 方法=128
ldap_1 | 5a795085 conn=1046 op=0 BIND dn="cn=admin,dc=example,dc=org" mech=SIMPLE ssf=0
ldap_1 | 5a795085 conn=1046 op=0 结果标签=97 err=0 文本=
ldap_1 | 5a795085 conn=1046 op=1 SRCH base="dc=example,dc=org" scope=2 deref=0 filter="(objectClass=*)"
ldap_1 | 5a795085 conn=1046 op=1 搜索结果标签=101 err=0 nentries=8 文本=
ldap_1 | 5a795085 conn=1046 op=2 解除绑定 ldap_1 | 5a795085 conn=1046 fd=16 关闭

我一直在寻找一段时间试图获得解决方案,但没有运气。我希望有人可以帮助我:D

编辑:仍然在没有运气的情况下解决这个问题:(

4

1 回答 1

1

尝试更新最新的 ldap3 和 pyasn1 版本。

于 2018-02-12T18:34:49.840 回答