AttributeError: module 'bcrypt' has no attribute 'hashpw' for python

与世无争的帅哥 提交于 2020-02-06 11:23:27

问题


I don't know what I'm doing wrong. Please help


回答1:


I ran into this issue as well and went through these steps to figure it out:

pip list double check that bcrypt is in that list

python --version which returned Python 2.7.15rc1

python3 --version which returned Python 3.6.7

I had an issue where python3 doesn't recognize the bcrypt package:

    python
    Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
    [GCC 7.3.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>import bcrypt (pressed enter here)
    >>>

vs

    python3
    Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
    [GCC 8.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import bcrypt
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'bcrypt'

then when double checking my file listing ran into the same issue @user2357112 suggested and renamed the "bcrypt.py" file I had created.

You stated that bcrypt.py is not the name of the file so I tried something else to recreate and built a new bcrypt.py file next to my pharaoh.py and reproduced the same error.

My code currently:

    #!/usr/bin/env python
    import bcrypt

    # raw_input for pv2
    user = raw_input("User value: \n")
    password = raw_input("password: \n")


    def pass_thru_crypt(user, password):
           user_password = user + password
           hashed = bcrypt.hashpw(user_password, bcrypt.gensalt())
           if bcrypt.checkpw(user_password, hashed):
               print("Indiana Jones just *bad_word* you up, Charlie!")
           else:
               print("You chose... poorly")

    pass_thru_crypt(user, password)


来源:https://stackoverflow.com/questions/53586448/attributeerror-module-bcrypt-has-no-attribute-hashpw-for-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!