2017-03-02 60 views
0

我想添加一個條目使用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函數內的某處失敗。

+0

你需要python代碼中的for循環嗎?看起來它只是將字典轉換爲字典? – Todor

+0

這只是我試過的試驗和錯誤之一。雖然這不是必要的,但它沒有任何區別。 – Arpitha

回答

0

python-ldap曾經有過使用Unicode字符串的問題 - 我很久沒用過了,不知道它是否在最新版本中修復過。

看看這個錯誤,這看起來就像這裏的情況 - 只要將任何unicode參數轉換爲字符串,例如使用RF Convert To String或Python的str()

編輯:例如,投名單成員:

${subscriber}  Convert To String subscriber 
${ObjList} Create List ${subs} 

類似的字典中的值。

+0

我明白,objectclass期望一個List作爲值。所以我通過了Robot。但我懷疑我沒有在python函數中處理得很好。 – Arpitha

+0

@Arpitha我的意思是列表成員和字典值是字符串類型(不是Unicode);我已經編輯了答案來舉個例子。 – Todor