title: python - flask_simpleldap won't bind
body: <p>I'm using <a href="https://github.com/admiralobvious/flask-simpleldap" rel="nofollow noreferrer">flask_simpleldap</a> and am struggling to get a bind connection to do anything useful.</p>
  
  <p>My LDAP server is active directory.  </p>
  
  <p>The stripped down code looks as follows, and looks almost identical to <a href="https://github.com/admiralobvious/flask-simpleldap/blob/master/examples/basic_auth/app.py" rel="nofollow noreferrer">the example</a>:</p>
  
  <pre><code>from flask import Flask
  from flask_simpleldap import LDAP
  
  app = Flask(__name__)
  app.secret_key = 'super secret key'
  app.debug = True
  
  app.config['LDAP_HOST'] = 'my-ldap-host.example.com'
  app.config['LDAP_REALM_NAME'] = 'LDAP Authentication'
  app.config['LDAP_SCHEMA'] = 'ldaps'
  app.config['LDAP_PORT'] = 636
  app.config['LDAP_BASE_DN'] = 'dc=example,dc=com'
  app.config['LDAP_USERNAME'] = 'binduser@example.com'
  app.config['LDAP_PASSWORD'] = 'binduser_pw'
  
  app.config['LDAP_OBJECTS_DN'] = 'distinguishedName'
  app.config['LDAP_OPENLDAP'] = False
  
  ldap = LDAP(app)
  
  
  @app.route('/ldap')
  @ldap.basic_auth_required
  def ldap_protected():
      return 'Welcome, {0}!'.format(g.ldap_username)
  
  if __name__ == '__main__':
      app.run(host='0.0.0.0', port=8080, debug=True)
  </code></pre>
  
  <p>When running the flask app, i'll get an error such as this:</p>
  
  <pre><code>LDAPException: Operations error
  </code></pre>
  
  <p>While trying to troubleshoot, i've modified <code>flask_simpleldap</code> <code>__init__.py</code> file to show the <code>info</code> as well as the <code>desc</code> of the error, on <a href="https://github.com/admiralobvious/flask-simpleldap/blob/master/flask_simpleldap/__init__.py#L274" rel="nofollow noreferrer">line 274</a>; Now i get a bit more info about the error: </p>
  
  <pre><code>LDAPException: 000004DC: LdapErr: DSID-0C090752, 
  comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580
  </code></pre>
  
  <p>So, i guess what i need to understand is why my initial bind won't work... do i have something wrong in my <code>app.config</code>? </p>
  
  <p>Not sure what the problem could be... <code>ldapsearch</code> seems to work from a shell as such:</p>
  
  <pre><code>ldapsearch -x -LLL -E pr=200/noprompt -h my-ldap-host.example.com -D "binduser@example.com" -w 'binduser_pw' -b "dc=example, dc=com" -s sub  "(sAMAccountName=binduser)"    | grep distinguishedName
  
  
  distinguishedName: CN=Bind User,OU=Some_OU,DC=example,DC=com
  </code></pre>
  
  <p><strong>Other details</strong>: </p>
  
  <ul>
  <li>I've tried on python2.7 and 3.5, same issues</li>
  <li>Centos 7.2 </li>
  <li>Active Directory is my LDAP server </li>
  </ul>
  
  <p>Any help appreciated, thanks. </p>