title: LDAPException: Invalid credentials flask_simpleldap
body: <p>I'm using <code>flask_simpleldap</code> to connect <code>ldap</code>. I use one github example you see in this <a href="https://github.com/admiralobvious/flask-simpleldap/blob/master/examples/groups/app.py" rel="nofollow noreferrer">link</a>. but I get wrong credential, actually the username and password is correct and I can connect with them with and open source client you seen in below screenshot. but with this code I get the error:</p>
  
  <p><a href="https://i.stack.imgur.com/uQuiJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uQuiJ.png" alt="enter image description here"></a></p>
  
  <pre><code>import ldap as l
  from flask import Flask, g, request, session, redirect, url_for
  from flask_simpleldap import LDAP
  
  app = Flask(__name__)
  app.secret_key = 'dev key'
  app.debug = True
  
  
  app.config['LDAP_HOST'] = '10.132.57.208'
  app.config['LDAP_BASE_DN'] = 'DC=mydomain,DC=com'
  app.config['LDAP_USERNAME'] = 'CN=jack,CN=jo,DC=mydomain,DC=com'
  app.config['LDAP_PASSWORD'] = '12345678'
  app.config['LDAP_CUSTOM_OPTIONS'] = {l.OPT_REFERRALS: 0}
  app.config['LDAP_USE_SSL'] = True
  
  
  ldap = LDAP(app)
  
  
  @app.before_request
  def before_request():
      g.user = None
      if 'user_id' in session:
          # This is where you'd query your database to get the user info.
          g.user = {}
          # Create a global with the LDAP groups the user is a member of.
          g.ldap_groups = ldap.get_user_groups(user=session['user_id'])
  
  
  @app.route('/')
  @ldap.login_required
  def index():
      return 'Successfully logged in!'
  
  
  @app.route('/login', methods=['GET', 'POST'])
  def login():
      if g.user:
          return redirect(url_for('index'))
      if request.method == 'POST':
          user = 'jack.jo'
          passwd = '12345678'
          test = ldap.bind_user(user, passwd)
          if test is None or passwd == '':
              return 'Invalid credentials'
          else:
              session['user_id'] = request.form['user']
              return redirect('/')
      return """&lt;form action="" method="post"&gt;
                  user: &lt;input name="user"&gt;&lt;br&gt;
                  password:&lt;input type="password" name="passwd"&gt;&lt;br&gt;
                  &lt;input type="submit" value="Submit"&gt;&lt;/form&gt;"""
  </code></pre>
  
  <p>and below is the trace:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
      return self.wsgi_app(environ, start_response)
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
      response = self.handle_exception(e)
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
      reraise(exc_type, exc_value, tb)
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
      response = self.full_dispatch_request()
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
      rv = self.dispatch_request()
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "/media/storage/portals/GRC_portal/test/app.py", line 55, in login
      test = ldap.bind_user(user, passwd)
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask_simpleldap/__init__.py", line 147, in bind_user
      user_dn = self.get_object_details(user=username, dn_only=True)
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask_simpleldap/__init__.py", line 179, in get_object_details
      conn = self.bind
    File "/media/storage/portals/GRC_portal/venv/lib/python2.7/site-packages/flask_simpleldap/__init__.py", line 125, in bind
      raise LDAPException(self.error(e.args))
  LDAPException: Invalid credentials
  </code></pre>