Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3:错误-Hashlib没有属性';SHA256&x27;_Python_Python 3.x_Hashlib - Fatal编程技术网

Python 3:错误-Hashlib没有属性';SHA256&x27;

Python 3:错误-Hashlib没有属性';SHA256&x27;,python,python-3.x,hashlib,Python,Python 3.x,Hashlib,引发错误:AttributeError:模块“hashlib”没有属性 “SHA256” 我发现与我的问题类似: 但是我对“导入hashlib”和打印(dir(hashlib))的输出是: import hashlib h = hashlib.SHA256(string) Python是区分大小写的,这意味着大写字母(大写)和小写字母(非大写)之间的区别很重要。 使用打印输出中显示的名称,例如sha256,而不是sha256 所以正确的代码是 ['__all__', '__builti

引发错误:AttributeError:模块“hashlib”没有属性 “SHA256”

我发现与我的问题类似:

但是我对“导入hashlib”
打印(dir(hashlib))
的输出是:

import hashlib    
h = hashlib.SHA256(string)

Python是区分大小写的,这意味着大写字母(大写)和小写字母(非大写)之间的区别很重要。 使用打印输出中显示的名称,例如
sha256
,而不是
sha256

所以正确的代码是

['__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']

如果需要,请使用sha256
import hashlib    
h = hashlib.sha256(string)