question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in bind_user method

See original GitHub issue

I’m on Python 3.6.3 and I get this exception when I hit line 153 in __init__.py (https://github.com/admiralobvious/flask-simpleldap/blob/master/flask_simpleldap/__init__.py#L153):

AttributeError: 'str' object has no attribute 'decode'

I changed it back to a recent commit you had in v1.1.2, which fixed the issue: conn.simple_bind_s(user_dn, password) (instead of conn.simple_bind_s(user_dn.decode('utf-8'), password))

Can we get that fix back?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lindycodercommented, Feb 8, 2018

i crafted a little monkey patch, works for me:

def _monkey_patch_openldap_string_flask_simpleldap_1_2_0_issue_44(ldap_instance):
    import ldap

    def bind_user(self, username, password):
        user_dn = self.get_object_details(user=username, dn_only=True)

        if user_dn is None:
            return
        try:
            if type(user_dn) == bytes:
                user_dn = user_dn.decode('utf-8')

            conn = self.initialize
            conn.simple_bind_s(user_dn, password)
            return True
        except ldap.LDAPError:
            return

    import types
    ldap_instance.bind_user = types.MethodType(bind_user, ldap_instance)

    return ldap_instance

app = Flask(__name__)
# set configs on app
ldap_auth = _monkey_patch_openldap_string_flask_simpleldap_1_2_0_issue_44(LDAP(app))

# use @ldap_auth.*

Have a nice day 😃

0reactions
VicenteIranzoMaestrecommented, May 29, 2019

Same issue, solved applying @lindycoder code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection reset by peer trying to use LDAP against AD
Hello,. Trying to use LDAP authentication against Active Directory (AD). According to known howtos, the below is in /etc/gitlab/gitlab.rb:
Read more >
Internal error in radius server with with bind DN | Security
The access tracker record shows the authentication method as "-". That is nothing. When I enable Bind User and it works, authentication method...
Read more >
Receiving "ldap operation failed: failed to bind as user" error ...
Introduction Problem When the LDAP authentication method is configured, the first Vault client login via the newly configured LDAP...
Read more >
Solved: Atlas LDAP authentication failed - Cloudera Community
I could log into ranger with LDAP ids ok, but atlas always returns me a error. log says "LDAP: error code 49 -...
Read more >
Add unexpected exception log when bind user can ... - GitHub
Preflight Checklist I have completed all Troubleshooting Steps. I'm on the latest version of Directus. There's no other issue that already ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found