我想用python(-ldap)脚本在AD中更改手机号码。
这是我试图使用的代码:
# import needed modules
import ldap
import ldap.modlist as modlist
# Open a connection
l = ldap.initialize("ldap://host/",trace_level=3)
# Bind/authenticate with a user with apropriate rights to add objects
l.simple_bind_s("user@domain","pw")
# The dn of our existing entry/object
dn="CN=common name,OU=Users,OU=x,DC=y,DC=z,DC=e"
# Some place-holders for old and new values
name = 'mobile'
nr1 = '+4712781271232'
nr2 = '+9812391282822'
old = {name:nr1}
new = {name:nr2}
# Convert place-holders for modify-operation using modlist-module
ldif = modlist.modifyModlist(old,new)
# Do the actual modification
l.modify_s(dn, ldif)
# Its nice to the server to disconnect and free resources when done
l.unbind_s()不幸的是,我得到了以下错误:
ldap.UNWILLING_TO_PERFORM:{'info':u'00000057: LdapErr: DSID-0C090FC7,注释:属性转换操作错误,数据0,v 4563‘,'desc':U’‘Server不愿执行’}
我可以通过保留旧的空来删除该条目,但是当我试图设置它时,我会得到以下内容:
LDAPError - TYPE_OR_VALUE_EXISTS:{'info':u'00002083: AtrErr: DSID-031519F7,#5:\n\t0: 00002083: DSID-031519F7,问题1006 (ATT_OR_VALUE_EXISTS),数据0,Att 150029 (移动):len 2\n\t1: 00002083: DSID-031519F7,问题1006 (ATT_OR_VALUE_EXISTS),数据0,Att 150029 (移动):len 2\n\t2: 00002083: DSID-031519F7,问题1006 (ATT_OR_VALUE_EXISTS),数据0,Att 150029 (移动):len 2\n\t3: 00002083: DSID-031519F7,问题1006 (ATT_OR_VALUE_EXISTS),数据0,Att 150029 (移动):len 2\n\t4: 00002083: DSID-031519F7,问题1006 (ATT_OR_VALUE_EXISTS),数据0,Att 150029 (移动):len 2\n','desc':U‘类型或存在的值’}
使用命令行工具ldapmodify,我能够做到这两点:
dn:CN=common name,OU=Users,OU=x,DC=y,DC=z,DC=e
changetype: modify
add: mobile
mobile: +1 2345 6789
dn:CN=common name,OU=Users,OU=x,DC=y,DC=z,DC=e
changetype: modify
delete: mobile
mobile: +1 2345 6789但无法做到这一点:
dn:CN=common name,OU=Users,OU=x,DC=y,DC=z,DC=e
changetype: modify
replace: mobile
mobile: +1 2345 6789
mobile: +4 567 89012345以下错误:
ldap_modify:违反约束(19)附加信息: 00002081: AtrErr: DSID-03151907,#1: 0: 00002081: DSID-03151907,问题1005 (CONSTRAINT_ATT_TYPE),数据0,Att 150029 (移动)
已经尝试了一段时间了,非常感谢你的帮助。
发布于 2020-02-23 15:36:43
别介意这个问题。取代:
nr1 = '+4712781271232'
nr2 = '+9812391282822'
old = {name:nr1}
new = {name:nr2}通过以下方式:
old = {'mobile':["+4712781271232"]}
new = {'mobile':["+9812391282822"]}(括号起作用;)
https://stackoverflow.com/questions/60363685
复制相似问题