【发布时间】:2021-04-17 19:27:05
【问题描述】:
我编写了以下代码,但问题是我收到了一个错误 (AttributeError: 'bytes' object has no attribute 'hexdigest')
错误语法不起作用
import requests
import hashlib
def request_api_data (query_char):
url = 'https://api.pwnedpasswords.com/range/'+ query_char
res = requests.get(url)
if res.status_code != 200:
print('it is an error')
#raise RuntimeError(f'Error fetching: {res.status_code}, check api and try again')
return res
request_api_data('123')
def pwned_api_check(password):
sha1password= hashlib.sha1(password.encode('utf-8').hexdigest().upper())
print (sha1password)
#return sha1password
pwned_api_check('123')
为什么会出现这个错误,我该如何解决??
【问题讨论】:
-
请将问题重命名为:“hashlib error: AttributeError: 'bytes' object has no attribute 'hexdigest'”
标签: python-3.x hex hashlib