【发布时间】:2021-09-25 13:30:30
【问题描述】:
我正在尝试验证从 Shopify 收到的 webhook,但 Hmac 验证失败。
def verify_webhook(data, hmac_header):
digest = hmac.new(SECRET.encode('utf-8'), data, hashlib.sha256).digest()
computed_hmac = base64.b64encode(digest)
return hmac.compare_digest(computed_hmac, hmac_header.encode('utf-8'))
@app.route('/productCreation', methods=['POST'])
def productCreation():
data = request.data
verified = verify_webhook(
data, request.headers.get('X-Shopify-Hmac-SHA256'))
if(verified):
return ("Success", 200)
return("Integrity error", 401)
得到错误
hash = hmac.new(SECRET.encode('utf-8'), body.encode('utf-8'), hashlib.sha256)
AttributeError: 'bytes' object has no attribute 'encode'
有人可以帮忙吗?我正在为此开发一个 Flask 应用程序。
【问题讨论】:
标签: python flask shopify hmac shopify-app