0

I have written a Python script and I am using ldap3 module ( https://pypi.org/project/ldap3/) to add,modify attribute value in Oracle ldap.

I am able to modify ldap attribute values that don't have a single quote in it. However some users they have a single quote (') in their name. when I try to update displayname for a user who has a single quote. I get an error below

conn is connection to Oracle ldap

dipslayName is : O'Sry, Harry

result = conn.modify('uid=Harry12,ou=Corporate,ou=org,dc=axe,dc=com',{'displayName':[(ldap3.MODIFY_REPLACE,['O'Sry, Harry'])]})

Error:
File "<string>", line 1
    {'displayName':[(ldap3.MODIFY_REPLACE,['O'Sry, Harry'])]} 
                                              ^
SyntaxError: invalid syntax

I have already tried escaping using \ as below

{'displayName':[(ldap3.MODIFY_REPLACE,['O\'Sry, Harry'])]}

How do I escape single quotes in displayname in ldap3.MODIFY_REPLACE.

vnode12
  • 1
  • 1

1 Answers1

1

This is a questione relevant to python, non to ldap3. In python you can use single or double quote as string delimiters. Try with double quote for defining the string:

“O'Sry, Harry”

So the single quote inside the string is not considered as a delimiter from the python interpreter.

cannatag
  • 1,528
  • 11
  • 17