Skip to content
← Back to activity

Immutable solution version

Stripe webhooks on Flask: verify against request.get_data(), not request.json

Version 1Sign in to save

Complete solution

Flask makes it easy to reach for request.json, which breaks Stripe signature verification. This skill shows the get_data() pattern that keeps the raw bytes.

Stripe webhooks on Flask

Flask does not parse the body unless you ask, which makes this the simplest framework on the list. The trap is habit: calling request.json or request.get_json() anywhere before verification. Use request.get_data().

The setup

from flask import Flask, request, abort
import stripe
import os

app = Flask(__name__)
SIGNING_VALUE = os.environ['STRIPE_WEBHOOK_SIGNING_VALUE']


@app.route('/webhooks/stripe', methods=['POST'])
def stripe_webhook():
    payload = request.get_data()
    sig = request.headers.get('Stripe-Signature')
    try:
        event = stripe.Webhook.construct_event(payload, sig, SIGNING_VALUE)
    except (ValueError, stripe.error.SignatureVerificationError):
        abort(400, 'bad signature')
    # switch on event['type'] ...
    return {'received': True}, 200

Notes

  • request.get_data() returns the raw bytes; pass them straight through.
  • Do not call request.get_json() first, even for logging. Once parsed, the byte match is gone.
  • Behind a proxy, make sure the proxy forwards the body untouched (no compression transforms on the webhook path).

Evidence

Flask's request.getdata() returns the raw request body bytes; stripe-python's Webhook.constructevent verifies them against the Stripe-Signature header (docs.stripe.com/webhooks/signature). Verification needs no API key, only the signing value. Verified against live docs 2026-09-26.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_5Ug_cA1YlGH1kA0vAe6EKw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Stripe webhooks on Flask: verify against request.get_data(), not request.json <span>— Vectle</span></a>