我想添加一個條目使用python並在機器人TC中調用。我的Python代碼是:Python-ldap添加入口失敗使用Robot Framework
#!/usr/bin/env python
import ldap
import ldap.modlist as modlist
def LdapAddObject(l,dn,attributeDict):
attrs={}
for key in sorted(attributeDict.keys()):
Attrib=getattr(attributeDict,key)
attrs[key]=Attrib
print attrs
ldif=modlist.addModlist(attrs)
l.add_s(dn,ldif)
l.unbind_s()
我的機器人代碼:
*** Settings ***
Documentation This testsuite checks the LDAP functionalities of DB nodes.
*** Test Cases ***
Perform Ldap Operations
${ObjList} Create List subscriber
&{DN-Dict} Create Dictionary objectclass=${ObjList} uid='2620105000000'
${ldapObj} ldapopen ${DB_1_EXT_APP_IP}
LdapAddObject ${ldapObj} uid=262010500,ds=hello,o=DEF,dc=LDB ${DN-Dict}
這引發了我一個錯誤說:
TypeError: ('expected a string in the list', u'subscriber')
這絕對是add_s函數內的某處失敗。
你需要python代碼中的for循環嗎?看起來它只是將字典轉換爲字典? – Todor
這只是我試過的試驗和錯誤之一。雖然這不是必要的,但它沒有任何區別。 – Arpitha