gpt4 book ai didi

django - Stripe 使用 django 的 webhook 说 : stripe. error.SignatureVerificationError

转载 作者:行者123 更新时间:2023-12-05 00:46:06 29 4
gpt4 key购买 nike

我使用与 stripe tutorial 中相同的代码:

def webhook(request):
payload = request.body
sig_header = request.META['HTTP_STRIPE_SIGNATURE']
event = None

try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)
except ValueError as e:
raise(e)
return HttpResponse(status=400)
except stripe.error.SignatureVerificationError as e:
raise(e)
return HttpResponse(status=400)

# ...

但是当我尝试使用 strip CLI (stripe trigger payment_intent.created) 测试 webhook 时,我遇到了这个错误:

Internal Server Error: /payment/webhook/
Traceback (most recent call last):
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/views/decorators/http.py", line 40, in inner
return func(request, *args, **kwargs)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/rouizi/django-ecommerce/payment/views.py", line 99, in webhook
raise(e)
File "/home/rouizi/django-ecommerce/payment/views.py", line 88, in webhook
payload, sig_header, endpoint_secret
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/stripe/webhook.py", line 23, in construct_event
WebhookSignature.verify_header(payload, sig_header, secret, tolerance)
File "/home/rouizi/django-ecommerce/venv/lib/python3.6/site-packages/stripe/webhook.py", line 78, in verify_header
payload,
stripe.error.SignatureVerificationError: No signatures found matching the expected signature for payload

我尝试像这样解码有效载荷:

payload = request.body.decode('utf-8')

但我仍然有同样的错误。

错误可能来自哪里?

最佳答案

事实证明,在测试模式下创建 webhook 时,它会为您提供与 CLI 相同的 webhook 密码。

您需要将此密码用作其他评论中所述的 webhook 密码。 enter image description here

关于django - Stripe 使用 django 的 webhook 说 : stripe. error.SignatureVerificationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61937183/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com