简体   繁体   中英

python-ldap error - {'desc': 'No such object'}

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:

username = "user@domain.com"

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:

username = "uid=%s,ou=People,dc=domain,dc=com" %('insert-username-here')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM