title: Python: how to get emails of Active Directory group members?
body: <p>I am trying to get all group members of Active Directory.</p>
  
  <p>I have this code:</p>
  
  <pre><code>    from ldap3 import Server, Connection, ALL, core
  
      server = Server(address, get_info=ALL)
      ad_conn = Connection(server, dn, password, auto_bind=True)
      members = []
      AD_GROUP_FILTER = '(&amp;(objectClass=GROUP)(cn={group_name}))'
      ad_filter = AD_GROUP_FILTER.replace('{group_name}', group_name)
      result = ad_conn.search_s('OU details', ldap3.SCOPE_SUBTREE, ad_filter)
      if result:
          if len(result[0]) &gt;= 2 and 'member' in result[0][1]:
              members_tmp = result[0][1]['member']
              for m in members_tmp:
                  email = get_email_by_dn(m, ad_conn)
                  if email:
                      members.append(email)
      return members
  </code></pre>
  
  <p>But I am getting an error </p>
  
  <blockquote>
    <p>'Connection' object has no attribute 'search_s'</p>
  </blockquote>