title: python-ldap unable to do any basic search queries on open server
body: <p>I have been trying to do some basic search queries, but I am unable to connect to an open LDAP server regardless. I tried a couple of servers, and none of them worked. I used Apache Directory Studio to make sure that the keyword was there but it did not work either way. I tried a variety of different code from different sources. 
  This was the first one I used 
  :
  <a href="https://www.linuxjournal.com/article/6988" rel="nofollow noreferrer">https://www.linuxjournal.com/article/6988</a></p>
  
  <pre><code>import ldap
  
  
  keyword = "boyle"
  def main():
      server = "ldap.forumsys.com"
      username = "cn=read-only-admin,dc=example,dc=com"
      password = "password"
  
      try:
          l = ldap.open(server)
          l.simple_bind_s(username,password)
          print "Bound to server . . . "
          l.protocol_version = ldap.VERSION3
          print "Searching . . ."
          mysearch (l,keyword)
  
      except ldap.LDAPError:
          print "Couldnt connect"
  
  def mysearch(l, keyword):
  
      base = ""
      scope = ldap.SCOPE_SUBTREE
      filter = "cn=" + "*" + keyword + "*"
  
      retrieve_attributes = None
  
      count = 0
      result_set = []
      timeout = 0
      try:
          result_id = l.search(base, scope, filter, retrieve_attributes)
  
          while l != 1:
              result_id = l.search(base, scope,filter, retrieve_attributes)
              result_type, result_data = l.result(result_id, timeout)
              if result_data == []:
                  break
              else:
                  if result_type == ldap.RES_SEARCH_ENTRY:
                      result_set.append(result_data)
  
          if len (result_set = 0):
              print "No Results"
  
          for i in range (len(result_set)):
              for entry in result_set[i]:
                  try:
                      name = entry[1]['cn'][0]
                      mail = entry[1]['mail'][0]
                      #phone = entry[1]['telephonenumber'][0]
                      #desc = entry[1]['description'][0]
                      count = count + 1
                      print name + mail
                  except:
                      pass
      except ldap.LDAPError, error_message:
          print error_message
  
  main()
  </code></pre>
  
  <p>Every time I ran this program, I received an error 
  {'desc': u"No such object"}</p>
  
  <p>I also tried this</p>
  
  <pre><code>import ldap
  
  try:
  
    l = ldap.open("ldap.example.com")
  
  
  except ldap.LDAPError, e:
    print e
  
  
  base_dn = "cn=read-only-admin,dc=example,dc=com"
  
  search_scope = ldap.SCOPE_SUBTREE
  retrieve_attributes = None
  search_filter = "uid=myuid"
  
  try:
    l_search = l.search(base_dn, search_scope, search_filter, retrieve_attributes)
    result_status, result_data = l.result(l_search, 0)
    print result_data
  except ldap.LDAPError, e:
    print e
  </code></pre>
  
  <p>The error on this one was 
  {'desc': u"Can't contact LDAP server"}</p>
  
  <p>I spent about 5 hours trying to figure this out. I would really appreciate it if you guys could give me some advice. Thanks.</p>