Reputation: 11
I would like to make a small ldap request but I am facing the following error. I don't see where the problem comes from, is it the request or the connection to the ldap server?
Python 3.6.8 (default, Nov 17 2021, 16:10:06)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ldap
>>> searchFilter = "uid=monutilisateur"
>>> basedn = "ou=People,dc=univ-sarthe,dc=fr"
>>> searchScope = "ldap.SCOPE_SUBTREE"
>>> searchAttribute= ['uid']
>>> connection = ldap.initialize('ldaps://ldap.univ-sarthe.fr:636')
>>> connection.set_option(ldap.OPT_REFERRALS, 0)
>>> connection.protocol_version = ldap.VERSION3
>>> connection.simple_bind_s('cn=monusertoconnect,ou=applications,dc=univ-sarthe,dc=fr', 'monusertoconnectpass')
(97, [], 1, [])
>>> ldap_result_id = connection.search_s(basedn, searchScope, searchFilter, searchAttribute)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib64/python3.6/site-packages/ldap/ldapobject.py", line 631, in search_s
return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout=self.timeout)
File "/usr/local/lib64/python3.6/site-packages/ldap/ldapobject.py", line 624, in search_ext_s
msgid = self.search_ext(base,scope,filterstr,attrlist,attrsonly,serverctrls,clientctrls,timeout,sizelimit)
File "/usr/local/lib64/python3.6/site-packages/ldap/ldapobject.py", line 620, in search_ext
timeout,sizelimit,
File "/usr/local/lib64/python3.6/site-packages/ldap/ldapobject.py", line 128, in _ldap_call
result = func(*args,**kwargs)
TypeError: an integer is required (got type str)
Upvotes: 1
Views: 312
Reputation: 935
You've set searchScope as the string
searchScope="ldap.SCOPE_SUBTREE"
but this needs to be an integer https://www.python-ldap.org/en/python-ldap-3.3.0/reference/ldap.html#ldap.LDAPObject.search_s
try just
searchScope=ldap.SCOPE_SUBTREE
Upvotes: 1