maxcountryman / flask-bcrypt

Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Home Page:http://readthedocs.org/docs/flask-bcrypt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: 'unicode' does not have the buffer interface

awang opened this issue · comments

I'm on python 2.7.8. Flask is giving me the following error:

[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/lib/python2.7/Flask-0.10.1-py2.7.egg/flask/app.py", line 1836, in __call__
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     return self.wsgi_app(environ, start_response)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/lib/python2.7/Flask-0.10.1-py2.7.egg/flask/app.py", line 1820, in wsgi_app
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     response = self.make_response(self.handle_exception(e))
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/lib/python2.7/Flask-0.10.1-py2.7.egg/flask/app.py", line 1403, in handle_exception
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     reraise(exc_type, exc_value, tb)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/lib/python2.7/Flask-0.10.1-py2.7.egg/flask/app.py", line 1817, in wsgi_app
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     response = self.full_dispatch_request()
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/lib/python2.7/Flask-0.10.1-py2.7.egg/flask/app.py", line 1477, in full_dispatch_request
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     rv = self.handle_user_exception(e)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/lib/python2.7/Flask-0.10.1-py2.7.egg/flask/app.py", line 1381, in handle_user_exception
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     reraise(exc_type, exc_value, tb)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/lib/python2.7/Flask-0.10.1-py2.7.egg/flask/app.py", line 1475, in full_dispatch_request
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     rv = self.dispatch_request()
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/lib/python2.7/Flask-0.10.1-py2.7.egg/flask/app.py", line 1461, in dispatch_request
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     return self.view_functions[rule.endpoint](**req.view_args)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/venv/lib/python2.7/site-packages/flask_mobility/decorators.py", line 35, in wrapper
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     return f(*args, **kwargs)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/webapp/view/landing.py", line 100, in login
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     if form.validate_on_submit():
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/venv/lib/python2.7/site-packages/flask_wtf/form.py", line 156, in validate_on_submit
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     return self.is_submitted() and self.validate()
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/venv/lib/python2.7/site-packages/wtforms/form.py", line 271, in validate
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     return super(Form, self).validate(extra)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/venv/lib/python2.7/site-packages/wtforms/form.py", line 130, in validate
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     if not field.validate(self, extra):
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/venv/lib/python2.7/site-packages/wtforms/fields/core.py", line 175, in validate
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     stop_validation = self._run_validation_chain(form, chain)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/venv/lib/python2.7/site-packages/wtforms/fields/core.py", line 195, in _run_validation_chain
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     validator(form, self)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/webapp/forms.py", line 19, in validate_email
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     if not user.is_correct_password(self.password.data):
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/webapp/models.py", line 330, in is_correct_password
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     if self._password and b.check_password_hash(self._password, plaintext+'-'+current_app.config['PASSWORD_SALT']):
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/venv/lib/python2.7/site-packages/flask_bcrypt.py", line 180, in check_password_hash
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     return safe_str_cmp(bcrypt.hashpw(password, unicode(pw_hash)), unicode(pw_hash))
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]   File "/home/albert/webapps/webapp/venv/lib/python2.7/site-packages/werkzeug/security.py", line 117, in safe_str_cmp
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1]     return _builtin_safe_str_cmp(a, b)
[Sat Oct 11 01:30:04 2014] [error] [client 127.0.0.1] TypeError: 'unicode' does not have the buffer interface

Looks similar to this issue: cryptojuice/flask-scrypt#6

Casting to unicode in flask_bcrypt.py::check_password_hash() seems to fix things:
return safe_str_cmp(unicode(bcrypt.hashpw(password, pw_hash)), unicode(pw_hash))

Can you give 0.7.0 a try?

This is fixed now.