Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Issue with bcrypt in python social app

When trying to register a user I would get ValueError message 'User already Exists.'. But the user doesn't exist. When I removed try/except from:

@classmethod
    def create_user(cls, username, email, password, admin=False):
        cls.create(
            username=username,
            email=email,
            password=generate_password_hash(password),
            is_admin=admin)

I get this error:

TypeError: hashpw() argument 1 must be str, not bytes

I'm using PyCharm.

2 Answers

Nathan Tallack
Nathan Tallack
22,164 Points

You might have wrong bcrypt being used. Perhaps py-bcrypt is installed and pip did not try to fetch the regular bcrypt for you when you installed flask.

Try this in your shell.

pip uninstall flask-bcrypt
pip uninstall bcrypt
pip install flask-bcrypt --ignore-installed --no-cache-dir

Tried uninstall/install, still same error.

Through PyCharm I uninstalled: flask-bcrypt 0.7.1, bcrypt 2.0, python-bcrypt 0.3.1, and py-bcrypt 0.4

and reinstalled then it worked.

Nathan Tallack
Nathan Tallack
22,164 Points

Yeah. It get's kinda tricky when that happens. I am not fluent enough with Python to understand what happens when modules conflict like that.

Take care that doing it through PyCharm may have only been at the project level, so you may run into the same problem with another project later.

When you find time you should fix it up systemwide so that future projects won't have the problem. :)

Great work!!! :D