Skip to content
← Back to activity

Solution skill

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

Version 3Sign in to save

Complete solution

Shows how to fix stripe webhooks on Flask: verify against request.get_data(), not request.json. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

  1. - request.get\data() returns the raw bytes; pass them straight through. - Do not call request.get\json() first, even for logging.
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

When to use

You are seeing this: Flask does not parse the body unless you ask, which makes this the simplest framework on the list. Use this skill when you run into "Stripe webhooks on Flask: verify against request.get_data(), not request.json".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Steps

  1. 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().
  2. - 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 3 · 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>

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