Error modlist.py in addModlist

Garland, Ken R garlandkr at gmail.com
Mon Mar 19 19:21:47 CET 2007


I've sliced together a script to add users to ldap, which works great.
however, now i'm implementing it into a webapp and having some issues.

--------------------
Spyce exception
File:	/home/kgarland/downloads/spyce-2.1/www/newadd.spy
Message: 	

AttributeError: 'str' object has no attribute 'keys'

Stack:	/usr/lib/python2.4/site-packages/ldap/modlist.py:34, in addModlist:

for attrtype in entry.keys():

newadd.spy:19, in passcheck:
		mymodlist = ldap.modlist.addModlist(entry)
--------------------

My code causing the issue:

--------------------
def passcheck(self, api, passwd, firstname, lastname, vamcdrop):
        import string, sys, ldap, crack, hashlib, base64
        try:
                crack.VeryFascistCheck(passwd)
        except ValueError, reason:
                print("Please use a different password, %s." % reason)
        else:
                l=ldap.initialize("ldaps://null")
                l.bind_s('cn=removed,dc=removed,dc=removed', 'removed')
                y = hashlib.sha1(passwd).digest()
                base64encode = base64.encodestring(y)
                userpass = string.rstrip(base64encode)
                uid = firstname.lower() + "." + lastname.lower()
                mydn = "uid=" + uid + ",ou=VA,dc=pharmacy,dc=com"
                entry = "{'uid': ['" + uid + "'], 'objectClass':
['top', 'inetOrgPerson'], 'userPassword': ['" + '{SHA}' + userpass +
"'], 'vamc': ['" + vamcdrop + "'], 'sn': ['" + lastname + "'],
'givenName': ['" + firstname + "'], 'cn': ['" + firstname + " " +
lastname + "']}"
                mymodlist = ldap.modlist.addModlist(entry)
                l.add_s(mydn, mymodlist)
                print "Adding the following information into LDAP:"
                print "<br>"
                print entry
--------------------

Looks like modlist is not happy with the string being presented to it.
Printing the entry variable gives the same results for both the webapp
and commandline.

Web:
{'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'],
'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'],
'givenName': ['null'], 'cn': ['null null']}

Shell:
{'uid': ['null.null'], 'objectClass': ['top', 'inetOrgPerson'],
'userPassword': ['{SHA}null'], 'vamc': ['null'], 'sn': ['null'],
'givenName': ['null'], 'cn': ['null null']}




More information about the python-ldap mailing list