0
I need to connect to a LDAP server using Python (Version 3.8.8) and I've already tried to replicate some examples such as those showed in the link bellow but none of them are working for me. I either get (TypeError: iter() returned non-iterator of type 'NoneType') or (PyAsn1Error: Attempted "__iter__" operation on ASN.1 schema object). It seems like ldap3 and python-ldap used in the examples were not updated to work with python 3.8.8. I would be very pleased if anyone could give me a real example of another existing library to connect a LPDAP server or help me with this issue. 

(1) https://sixfeetup.com/blog/new-ldap3-python-ldap-library
(2) https://ldap3.readthedocs.io/en/latest/tutorial_intro.html
(3) https://stackoverflow.com/questions/58907026/ldap3-bind-failed-when-cn-and-displayname-are-different

my test error for the example in link 3:

from ldap3 import Server, Connection
server = Server('ipa.demo1.freeipa.org')
conn = Connection(server)
conn.bind()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
ipython-input-4-470896b147da> in <module>
      2 server = Server('ipa.demo1.freeipa.org')
      3 conn = Connection(server)
----> 4 conn.bind()

C:\ProgramData\Anaconda3\lib\site-packages\ldap3\core\connection.py in bind(self, read_server_info, controls)
    418                     if log_enabled(PROTOCOL):
    419                         log(PROTOCOL, 'anonymous BIND request <%s> sent via <%s>', bind_request_to_dict(request), self)
--> 420                     response = self.post_send_single_response(self.send('bindRequest', request, controls))
    421                 elif self.authentication == SIMPLE:
    422                     if log_enabled(PROTOCOL):

C:\ProgramData\Anaconda3\lib\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)

C:\ProgramData\Anaconda3\lib\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)

C:\ProgramData\Anaconda3\lib\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']:

C:\ProgramData\Anaconda3\lib\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)

C:\ProgramData\Anaconda3\lib\site-packages\ldap3\operation\bind.py in bind_response_to_dict(response)
    116             'dn': str(response['matchedDN']),
    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 

C:\ProgramData\Anaconda3\lib\site-packages\ldap3\protocol\convert.py in referrals_to_list(referrals)
     42 
     43 def referrals_to_list(referrals):
---> 44     return [str(referral) for referral in referrals if referral] if referrals else None
     45 
     46 

C:\ProgramData\Anaconda3\lib\site-packages\pyasn1\type\base.py in __bool__(self)
    572     else:
    573         def __bool__(self):
--> 574             return bool(self.components)
    575 
    576     @property

C:\ProgramData\Anaconda3\lib\site-packages\pyasn1\type\univ.py in components(self)
   1958     def components(self):
   1959         return [self._componentValues[idx]
-> 1960                 for idx in sorted(self._componentValues)]
   1961 
   1962     def clear(self):
TypeError: iter() returned non-iterator of type 'NoneType'
Cesarmsk
  • 11
  • 3

1 Answers1

0

It was a problem of library version... I ran the "pip install ldap3 upgrade" command and it worked fine

Cesarmsk
  • 11
  • 3