Python 3:错误 - Hashlib 没有属性 'SHA256'
Python 3: Error - Hashlib has no attribute 'SHA256'
import hashlib
h = hashlib.SHA256(string)
Error raised: AttributeError: module 'hashlib' has no attribute
'SHA256'
我发现 this 与我的问题相似:
但我对 "import hashlib" 和 print(dir(hashlib))
的输出是:
['__all__', '__builtin_constructor_cache', '__builtins__', '__cached__',
'__doc__', '__file__', '__get_builtin_constructor', '__loader__',
'__name__', '__package__', '__spec__', '_hashlib', 'algorithms_available',
'algorithms_guaranteed', 'blake2b', 'blake2s', 'md5', 'new', 'pbkdf2_hmac',
'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384',
'sha3_512', 'sha512', 'shake_128', 'shake_256']
Python 区分大小写,这意味着大写字母(大写)与小写字母(非大写)之间的区别很重要。
使用打印输出中显示的名称,例如 sha256
而不是 SHA256
所以正确的代码是
import hashlib
h = hashlib.sha256(string)
import hashlib
h = hashlib.SHA256(string)
Error raised: AttributeError: module 'hashlib' has no attribute 'SHA256'
我发现 this 与我的问题相似:
但我对 "import hashlib" 和 print(dir(hashlib))
的输出是:
['__all__', '__builtin_constructor_cache', '__builtins__', '__cached__',
'__doc__', '__file__', '__get_builtin_constructor', '__loader__',
'__name__', '__package__', '__spec__', '_hashlib', 'algorithms_available',
'algorithms_guaranteed', 'blake2b', 'blake2s', 'md5', 'new', 'pbkdf2_hmac',
'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384',
'sha3_512', 'sha512', 'shake_128', 'shake_256']
Python 区分大小写,这意味着大写字母(大写)与小写字母(非大写)之间的区别很重要。
使用打印输出中显示的名称,例如 sha256
而不是 SHA256
所以正确的代码是
import hashlib
h = hashlib.sha256(string)