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

TypeError: 'unicode' does not have the buffer interface #17

Closed
clebio opened this issue Jul 5, 2014 · 6 comments
Closed

TypeError: 'unicode' does not have the buffer interface #17

clebio opened this issue Jul 5, 2014 · 6 comments

Comments

@clebio
Copy link

clebio commented Jul 5, 2014

I'm attempting to use this repo for the first time as I work through the book. I run into an error when trying to log in, after creating a user. I've tried going through the new user registration flow within the app (though I don't have gmail configured) and also tried adding a user as the book describes in chapter eight:

$ ./manage.py shell
>>> u = User(email='john@example.com', username='john', password='cat')
>>> db.session.add(u)
>>> db.session.commit()

From the terminal, the error shows as:

 $ ./manage.py runserver
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader
127.0.0.1 - - [04/Jul/2014 19:08:05] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [04/Jul/2014 19:08:06] "GET /auth/login HTTP/1.1" 200 -
127.0.0.1 - - [04/Jul/2014 19:08:17] "POST /auth/login HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/caleb/dev/flasky/app/auth/views.py", line 13, in login
    if user is not None and user.verify_password(form.password.data):
  File "/home/caleb/dev/flasky/app/models.py", line 33, in verify_password
    return check_password_hash(self.password_hash, password)
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/werkzeug/security.py", line 224, in check_password_hash
    return safe_str_cmp(_hash_internal(method, salt, password)[0], hashval)
  File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/werkzeug/security.py", line 117, in safe_str_cmp
    return _builtin_safe_str_cmp(a, b)
TypeError: 'unicode' does not have the buffer interface

The full error on the app itself is:

TypeError
TypeError: 'unicode' does not have the buffer interface

Traceback (most recent call last)
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/caleb/dev/flasky/app/auth/views.py", line 13, in login
if user is not None and user.verify_password(form.password.data):
File "/home/caleb/dev/flasky/app/models.py", line 33, in verify_password
return check_password_hash(self.password_hash, password)
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/werkzeug/security.py", line 224, in check_password_hash
return safe_str_cmp(_hash_internal(method, salt, password)[0], hashval)
File "/home/caleb/.virtualenvs/flasky/lib/python2.7/site-packages/werkzeug/security.py", line 117, in safe_str_cmp
return _builtin_safe_str_cmp(a, b)
TypeError: 'unicode' does not have the buffer interface
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
Brought to you by DON'T PANIC, your friendly Werkzeug powered traceback interpreter.
@miguelgrinberg
Copy link
Owner

Looks like this is an issue in Werkzeug when you use Python 2.7.7. Here is the bug report. I think the easiest workaround is to downgrade to Python 2.7.6.

@clebio
Copy link
Author

clebio commented Jul 5, 2014

Ok, thanks for the quick response! I couldn't tell whether I'd maybe left a step out (db init, migrate, runserver, etc.) that was necessary.

Understanding the bug you linked to, I was able to resolve this just by modifying my python 2.7 virtualenv:

cdsitepackages
vim werkzeug/security.py

Searched for _builtin_safe_str_cmp and add bytes as described. That fixed it for me.

My user was still unconfirmed, but I resolved that by just setting 'confirmed' when adding the user at the manage.py shell:

u = User(email='biff@example.com', username='biff', password='cat', confirmed=True)

@clebio clebio closed this as completed Jul 5, 2014
@miguelgrinberg
Copy link
Owner

Great, glad you figured out a workaround. Note that in this application all users are created unconfirmed. Each user receives an email with a confirmation link, the state changes to confirmed when the link is clicked.

@jwieland
Copy link

Another way to solve the issues is upgrading Werkzeug from 0.9.4 to 0.9.6

@miguelgrinberg
Copy link
Owner

Yes, looks like they released a fixed for this bug now, but note it is 0.9.5 the version that includes this fix.

russomi pushed a commit to russomi-labs/flasky-appengine that referenced this issue May 15, 2015
@hugoeiji
Copy link

hugoeiji commented Jun 25, 2016

I updated to 0.9.6 and now the error is also gone :)

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

4 participants