gpt4 book ai didi

python - 无法导入 "hashlib"

转载 作者:太空狗 更新时间:2023-10-30 00:57:33 24 4
gpt4 key购买 nike

我试图用 sha1 加密一个字符串,但我从服务器收到一个错误:

"No Module Named hashlib"

通过使用以下代码:


import hashlib
encrypted = hashlib.sha1(string)
encrypted = encrypted.digest()

我将不胜感激,

谢谢,盖多尔

最佳答案

您的 Python 版本可能 < 2.5。使用 sha模块代替。

区别如下:

>>> import sha
>>> s = sha.new()
>>> s.update('hello')
>>> s.digest()
'\xaa\xf4\xc6\x1d\xdc\xc5\xe8\xa2\xda\xbe\xde\x0f;H,\xd9\xae\xa9CM'

对比

>>> import hashlib
>>> hashlib.sha1('hello').digest()
'\xaa\xf4\xc6\x1d\xdc\xc5\xe8\xa2\xda\xbe\xde\x0f;H,\xd9\xae\xa9CM'

关于python - 无法导入 "hashlib",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com