How to get access to the raw request body? #3772
-
I’m on Pyramid 2.0.2. Two days ago a Stripe webhook failed when it called back to the server:
According to the Stripe docs (link) and a Stackoverflow discussion (link) the issue may be that the Stripe code receives a modified request body, and thus fails. My code in the Pyramid request handler that receives the Stripe webhook request is like so: @view_config(
route_name="stripe_webhooks_callback",
request_method="POST",
)
def stripe_webhook(request):
try:
webhook_secret = config.get("stripe.webhook_secret")
event = stripe.Webhook.construct_event(request.body, request.headers["Stripe-Signature"], webhook_secret)
except stripe.error.SignatureVerificationError:
... This code has been running for a long time, and according to the docs (link) I just want to rule out that the body might have been JSON pretty-printed or been modified in another way? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I’m unaware of any features in webob or pyramid that modify the raw |
Beta Was this translation helpful? Give feedback.
-
If it only happened once, maybe it was a malformed when derived by stripe. Have you code to reproduce using test stripe API? Do you know the type of webhook that failed offhand or more about the structure of the request that failed? I don't use any webhooks yet in makepostsell.com |
Beta Was this translation helpful? Give feedback.
I’m unaware of any features in webob or pyramid that modify the raw
request.body
attribute. It is truncated at the content length iirc but that’s about it.