Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind_user() fails in Python3 #42

Closed
matthazinski opened this issue Nov 28, 2017 · 3 comments
Closed

bind_user() fails in Python3 #42

matthazinski opened this issue Nov 28, 2017 · 3 comments

Comments

@matthazinski
Copy link

This might be a regression between 1.1.2 and 1.2.0:

ae9eecf#diff-df961969fdc0fcec2f458e0fbb16eef9R153

Traceback:

[2017-11-28 19:13:08,163] ERROR in app: Exception on /api/v1/login [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "./test_api/api/v1/views.py", line 141, in login
    test = ldap.bind_user(user, passwd)
  File "/usr/local/lib/python3.5/dist-packages/flask_simpleldap/__init__.py", line 153, in bind_user
    conn.simple_bind_s(user_dn.decode('utf-8'), password)
AttributeError: 'str' object has no attribute 'decode'
[pid: 76|app: 0|req: 1/1] XXX.XXX.XXX.XXX () {40 vars in 802 bytes} [Tue Nov 28 19:13:06 2017] POST /api/v1/login =>
 generated 291 bytes in 1897 msecs (HTTP/1.1 500) 2 headers in 84 bytes (1 switches on core 0)

Changing this to conn.simple_bind_s(user_dn, password) seems to fix the problem for me.

@alexferl
Copy link
Owner

It's because user_dn is supposed to be bytes, this line is supposed to return bytes but it doesn't in your case for some reason.

I cannot reproduce your issue with the following environment on Python 3.6:

Flask==0.12.2
-e git+git@github.com:admiralobvious/flask-simpleldap.git@ae9eecff76b13a031bda56e55ed19f8e7c899eef#egg=Flask_SimpleLDAP
pyldap==2.4.45

What are you using?

@matthazinski
Copy link
Author

I'm on Python 3.5.2, Flask==0.12.1, Flask-SimpleLDAP==1.2.0, and pyldap==2.4.45. Upgrading to Flask==0.12.2 doesn't seem to change anything.

From here, records[0][0] is a str within a tuple within a list.

@alexferl
Copy link
Owner

Moving discussion to #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants