title: LDAP Query in Python3
body: <p>I have an LDAP Query which is running perfectly fine in my terminal</p>
  <pre><code>ldapsearch -h ldap.mygreatcompany.com -D user@mygreatcompany.COM -w &quot;$ldappassword&quot; -b &quot;DC=abc,DC=mygreatcompany,DC=com&quot; -s sub &quot;(mail=user1@mygreatcompany.COM)&quot; sAMAccountName
  
  </code></pre>
  <p>I want to run this command in python3, I followed other answers from StackOverflow and wrote something like this,</p>
  <pre><code>import ldap
  l = ldap.initialize('ldap://ldap.mygreatcompany.com')
  
  binddn = &quot;user@mygreatcompany.COM&quot;
  pw = #ldappassword
  basedn = &quot;DC=abc,DC=mygreatcompany,DC=com&quot;
  searchAttribute = [&quot;sAMAccountName&quot;]
  searchFilter = &quot;(&amp;(mail=user1@mygreatcompany.COM')(objectClass=*))&quot;
  searchScope = ldap.SCOPE_SUBTREE
  
  l.simple_bind_s(binddn, pw) 
  ldap_result_id = l.search_s(basedn, searchScope, searchFilter, searchAttribute)
  
  #Get result
  
  l.unbind_s()
  </code></pre>
  <p>But Here I am not getting the result from ldap_result_id. Can anybody help what is the correct way to do this query?</p>
  <p>Thanks</p>