简体   繁体   English

添加条目Python-LDAP

[英]Add Entries Python-LDAP

I'm trying to add entries with python ldap. 我正在尝试使用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. 我基本上是在制作django网络表单来进行用户管理。

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()

I speculate (but have not tested to prove it) that the root cause of your error is that your entry does not contain a "naming attribute" that matches the leftmost attribute in the DN of your entry, which in your case is ou=Enki Users. 我推测(但未经测试证明)错误的根本原因是您的条目不包含与条目DN中最左边的属性匹配的“命名属性”,在您的情况下为ou = Enki用户。 To add this naming attribute to the entry, you can add the following line in the part of your code that populates the attrs dict. 要将此命名属性添加到条目中,可以在填充attrs dict的代码部分中添加以下行。

attrs['ou'] = 'Enki Users' attrs ['ou'] ='Enki用户'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM