【发布时间】:2022-01-21 20:46:48
【问题描述】:
我想散列一些 4 位数字 但它给了我(对象支持所需的缓冲区 API)错误
这是我的代码
import hashlib
import itertools as it
number=[0,1,2,3,4,5,6,7,8,9]
code = hashlib.sha256()
passwords = list(it.permutations(number, 4))
#hpass is hash password
for hpass in passwords :
code.update(passwords)
print(hpass)
输出是
Traceback (most recent call last):
File "c:\Users\Parsa\Desktop\project\Untitled-2.py", line 11, in <module>
code.update(passwords)
TypeError: object supporting the buffer API required
【问题讨论】:
-
将字符串对象送入 update() 不起作用。哈希适用于字节而不是字符。尝试将其转换为字节,然后追加。
标签: python python-3.x hash