如何解决AttributeError: 'bytes' 对象没有属性 'hexdigest'
我编写了以下代码,但问题是我收到一个错误 (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.sha1(password.encode('utf-8')
后添加一个括号,以便在其上调用 hexdigest().upper()
。
以下代码对我有用:
hashlib.sha1(password.encode('utf-8')).hexdigest().upper()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。