Search code examples
pythonrobotframeworkpython-ldap

Python-ldap Add entry fails using Robot Framework


I am trying to add an entry using python and calling that in a Robot TC. My python code is :

#!/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()

My Robot code is :

*** 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}

It throws me an error saying :

TypeError: ('expected a string in the list', u'subscriber')

It is definitely failing somewhere within the add_s function.


Solution

  • python-ldap used to have problems with Unicode strings - I haven't used it in a long time, not sure is it fixed in the latest versions.

    Looking at the error, this looks like the case here though - just convert any unicode arguments to string, e.g. using the RF Convert To String or python's str()

    Edit: for example, cast the list member:

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

    Similar for the dictionary values.