简体   繁体   中英

Python-LDAP empty result in search_s

I've looked at a few examples and responses, however, I'm stumped. It worked a few minutes ago and now it's just not returning a result. No code change happened.

The test code I have pulls the members from a LDAP role group and prints the member DN's. It worked a few minutes ago, and now it keeps returning empty results. I also printed the ldap_result and it's empty too.

def ldapgroupmembers():
    try:
        username = str(raw_input('Email: '))
        password = str(getpass.getpass())
        l = ldap.initialize("ldap://company.co.za")
        l.simple_bind_s(username, password)
        myfilter = "(&DN=GROUP)(cn=My-RG-Group))"
        ldap_result = l.search_s("OU=MyGroups,OU=Role Groups,OU=Groups,OU=CompanyOU,DC=company,DC=co,DC=za", ldap.SCOPE_SUBTREE, myfilter, ['member'])
        for dn in ldap_result[0][1]['member']:
            print dn
    except ldap.INVALID_CREDENTIALS:
        print "Invalid credentials"
        return "Invalid credentials"
    except ldap.SERVER_DOWN:
        print "Server down"
        return "Server down"
    except ldap.LDAPError, e:
        if type(e.message) == dict and e.message.has_key('desc'):
            return "Other LDAP error: " + e.message['desc']
        else:
            print "Other LDAP error: "
            return "Other LDAP error: " + e
    finally:
        l.unbind_s()
    return "Succesfully authenticated"

Your help would be greatly appreciated.

I found the problem. Turns out I never closed the myfilter bracket and I removed the first bracket set where I filter on dn=GROUP

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