[英]python-ldap Modify phone number
我想使用 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,v4563','desc':u'服務器不願意執行'}
我可以通過將舊條目留空來刪除條目,但是當我嘗試設置它時,我得到以下信息:
LDAPError - TYPE_OR_VALUE_EXISTS: {'info': u'00002083: AtrErr: DSID-031519F7, #5:\\n\\t0: 00002083: DSID-031519F7, 問題 1006 (ATT_IST_OR_VAL,SLE_2006) (ATT_IST_OR_VALUE_1200) \\n\\t1: 00002083: DSID-031519F7, 問題 1006 (ATT_OR_VALUE_EXISTS), 數據 0, Att 150029 (mobile):len 2\\n\\t2: 00002083: DSID-0315102083: DSID-0315102083: DSID-0315102083: DSID-0315102083: DSID-0315102083: DSID-031519F7, 數據 0, 數據 0, ATT_OR_VALUE_EXISTS, 數據 05006, 數據 10UE 06, (移動):len 2\\n\\t3: 00002083: DSID-031519F7, 問題 1006 (ATT_OR_VALUE_EXISTS), 數據 0, Att 150029 (mobile):len 2\\n\\t4: 00002083: DSID-0703, 問題 150029 , data 0, Att 150029 (mobile):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), data 0, AtrErr: DSID-03151907
現在已經嘗試了一段時間,非常感謝一些幫助。
別管這個問題。 替換:
nr1 = '+4712781271232'
nr2 = '+9812391282822'
old = {name:nr1}
new = {name:nr2}
和:
old = {'mobile':["+4712781271232"]}
new = {'mobile':["+9812391282822"]}
括號可以解決問題;)
另外,我認為移動屬性可以定義為單值類型而不是多個。 但很高興您發現了語法錯誤!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.