Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ldap添加项使用Robot框架失败_Python_Robotframework_Python Ldap - Fatal编程技术网

Python ldap添加项使用Robot框架失败

Python ldap添加项使用Robot框架失败,python,robotframework,python-ldap,Python,Robotframework,Python Ldap,我正在尝试使用python添加一个条目,并在Robot TC中调用它。我的python代码是: #!/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[

我正在尝试使用python添加一个条目,并在Robot TC中调用它。我的python代码是:

#!/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_函数中的某个地方失败了

python ldap过去在Unicode字符串方面存在问题-我很久没有使用它了,不确定它在最新版本中是否已修复

看看这个错误,这里看起来是这样的-只需将任何unicode参数转换为字符串,例如使用RF
convert to string
或python的
str()

编辑:例如,强制转换列表成员:

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

字典值类似。

python代码中是否需要
for
循环-看起来它只是将dict转换为dict?这只是我尝试过的尝试和错误之一。但这并不需要。。我知道objectclass需要一个列表作为值。所以我也通过了机器人。但是我怀疑我在python函数中没有很好地处理它。@Arpitha我的意思是列表成员和字典值是字符串类型(不是Unicode);我编辑了答案以给出一个例子。