Django/Python-ldap Ldap Question Adding Entries

69 views
Skip to first unread message

G Z

unread,
Jul 23, 2014, 5:05:49 PM7/23/14
to django...@googlegroups.com
I'm trying to add entries via a form post in django, I have the following code and its really not django specific but it is python-ldap specific.


I'm trying to add entries with python ldap. I'm getting a naming convention error. My code is

    import ldap 
    import ldap.modlist as modlist
    
    LOGIN = "" 
    PASSWORD = '' 
    LDAP_URL = "ldap://127.0.0.1:389
    user='grant'
    l = ldap.initialize(LDAP_URL) 
    l.bind(LOGIN, PASSWORD) 
    dn="ou=Enki Users,dc=enki,dc=local" 
    
    attrs = {}
    attrs['objectclass'] = ['top','organizationalRole','simpleSecurityObject']
    attrs['cn'] = 'test'
    attrs['userPassword'] = 'test'
    attrs['description'] = 'User object for replication using slurpd'
    
    # Convert our dict to nice syntax for the add-function using modlist-module
    ldif = modlist.addModlist(attrs)
    
    # Do the actual synchronous add-operation to the ldapserver
    l.add_s(dn,ldif)
    
    # Its nice to the server to disconnect and free resources when done
    l.unbind_s()

The error is:

    ldap.NAMING_VIOLATION: {'info': "00002099: NameErr: DSID-0305109C, problem 2005 (NAMING_VIOLATION), data 0, best match of:\n\t'dc=enki,dc=local'\n", 'desc': 'Naming violation'}



The code that runs but doesn't insert the user into the correc organizational unit is the following code. However even though it runs I can't find the user in active directory. Please help me find whats wrong. I'm basically making a django webform for user management.

    import ldap 
    import ldap.modlist as modlist
    
    LOGIN = "" 
    PASSWORD = '' 
    LDAP_URL = "ldap://127.0.0.1:389
    user='grant'
    l = ldap.initialize(LDAP_URL) 
    l.bind(LOGIN, PASSWORD) 

    dn="cn=test,ou=Enki Users,dc=enki,dc=local" 
    
    attrs = {}
    attrs['objectclass'] = ['top','organizationalRole','simpleSecurityObject']
    attrs['cn'] = 'test'
    attrs['userPassword'] = 'test'
    attrs['description'] = 'User object for replication using slurpd'
    
    # Convert our dict to nice syntax for the add-function using modlist-module
    ldif = modlist.addModlist(attrs)
    
    # Do the actual synchronous add-operation to the ldapserver
    l.add_s(dn,ldif)
    
    # Its nice to the server to disconnect and free resources when done
    l.unbind_s()

Paul J Stevens

unread,
Jul 27, 2014, 12:32:55 PM7/27/14
to django...@googlegroups.com
Does ou=Enki Users,dc=enki,dc=local actually exist already?

If it doesn't you need to create it first before trying to add objects
to it.
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a2400449-3f68-4f9c-9d8e-b2d94d0d69f5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a2400449-3f68-4f9c-9d8e-b2d94d0d69f5%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
________________________________________________________________
Paul J Stevens pjstevns @ gmail, twitter, github, linkedin
www.nfg.nl/in...@nfg.nl/+31.85.877.99.97
Reply all
Reply to author
Forward
0 new messages