Adding objectClass to existing dn

Mark Roach mrroach at okmaybe.com
Tue Feb 1 16:24:33 CET 2005


On Tue, 2005-02-01 at 14:37 +0100, Robert Cooke wrote:
> Hi,
> 
> I've been trying to add an objectClass to an existing dn.
> Now I get messages like :

> {'info': "attribute 'cn' not allowed", 'desc': 'Object class violation'}
> {'info': 'modify/add: objectClass: value #0 already exists', 'desc':
> 'Type or value exists'}

I'm not sure how you're building your modlist, but you might want to
using ldap.modlist: (example off the top of my head, may have typos)

import ldap
import ldap.modlist
import copy

l = ldap.initialize('ldap://server')
l.bind_s('...', 'pass')
dn, attrs = l.search_s(dn, ldap.SCOPE_BASE)

newattrs = copy.deepcopy(attrs)
newattrs['objectClass'].append('newobjectclass')
newattrs['cn'] = ('cn_value',)

mlist = ldap.modlist.modifyModlist(attrs, newattrs)
l.modify_s(dn, mlist)


-Mark








More information about the python-ldap mailing list