[mod_python] ldap woes

Joshua Ginsberg listspam at flowtheory.net
Fri Aug 11 15:08:41 EDT 2006

Well, and further thoughts....

> import ldap
> ldapServer = ''
> ldapConfig = 'uid=%s,ou=people,dc=assembleco,dc=x'
> l = ldap.open(ldapServer)
> if password == "":
> 	password = "wrong"

That is just awful -- what if somebody chooses (FSM forbid) the a
password of "wrong"?

> try:
> 	l.simple_bind_s(ldapConfig % ('%s'%username), ('%s'%password))

What's with the extra string formatting? Just use:

l.simple_bind_s(ldapConfig % username, password)

And where are the values of username and password coming from?

> except ldap.LDAPError, e:
> 	print e

In this case "e" is an instance of the Exception class. It's not
necessarily predictable how this will get rendered as a string. And
under mod_python printing to stdout won't do anything -- you're not
running this under CGI, are you?

> #
> Under mod_python, it fails with the following error:
> {'desc': 'Encoding error'}

How about giving a more complete stack trace?


More information about the Mod_python mailing list