title: How should I escape ldap special characters?
body: <p>I'm using python-ldap to query Active Directory</p>
  
  <p>I have this DN </p>
  
  <pre><code>CN=Whalen\, Sean,OU=Users,OU=Users and Groups,DC=example,DC=net
  </code></pre>
  
  <p>That works fine as a base in a query, but if I try to use it in a search filter like this</p>
  
  <pre><code>(&amp;(objectClass=group)(memberof:1.2.840.113556.1.4.1941:=CN=Whalen\, Sean,OU=Users,OU=Users and Groups,DC=example,DC=net))
  </code></pre>
  
  <p>I get a <code>Bad search filter</code> error. From my testing, the comma in the CN seems to be the culprit, even though I escaped it with a backslash (<code>\</code>). But, comma isn't  listed in the <a href="http://social.technet.microsoft.com/wiki/contents/articles/5312.active-directory-characters-to-escape.aspx#LDAP_Filters" rel="nofollow">Microsoft documentation</a> as a character that needs escaped in filters.</p>
  
  <p>What am I missing? </p>