小编DEV*_*911的帖子

'bytes'对象没有'encode'属性

在将每个文档插入集合之前,我正在尝试存储salt和哈希密码.但在编码salt和密码时,它显示以下错误:

 line 26, in before_insert
 document['salt'] = bcrypt.gensalt().encode('utf-8')

AttributeError: 'bytes' object has no attribute 'encode'
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

def before_insert(documents):
    for document in documents:
        document['salt'] = bcrypt.gensalt().encode('utf-8')
        password = document['password'].encode('utf-8')
        document['password'] = bcrypt.hashpw(password, document['salt'])
Run Code Online (Sandbox Code Playgroud)

我在virtualenv中使用eve框架和python 3.4

python bcrypt python-3.x

15
推荐指数
1
解决办法
6万
查看次数

标签 统计

bcrypt ×1

python ×1

python-3.x ×1