So, I am trying to run a search with ldap, and trying to check if I am able to initialize it first. However, I keep getting the error {'desc': 'No such object'} I even tried wrong credentials but I don't even get to that error message. If someone could shed light on this, it'd be really helpful. Thanks in advance!
#!/usr/bin/python
import os, os.path
import subprocess as sp
import ldap
l = ldap.initialize('ldap://ldap.domain.com')
username = "uid=%s,ou=People,dc=domain,dc=com"
password = "password"
try:
    l.protocol_version = ldap.VERSION3
    l.simple_bind_s(username, password)
    valid = True
except Exception, error:
    print error
except ldap.INVALID_CREDENTIALS:
  print "Your username or password is incorrect."
  sys.exit(0)
 
                        
I was getting the same error. A quick and dirty fix to successfully bind is to change the username variable:
the problem with your variable is that the %s is a string formatting syntax (which it borrows from C). the proper use of that variable would look something like: