By Hanzalah Seikhai, payment integration developer. 3 December 2026

Stripe webhook signature verification failed in Django or FastAPI: the fixes

In Python the cause is almost always the same as in other stacks: the body Stripe signed is not the body your code verifies. Here is the working version for both frameworks, then the other causes.

Django

import stripe
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST

@csrf_exempt
@require_POST
def stripe_webhook(request):
    payload = request.body                      # raw bytes
    sig = request.META.get('HTTP_STRIPE_SIGNATURE')
    try:
        event = stripe.Webhook.construct_event(payload, sig, settings.STRIPE_WEBHOOK_SECRET)
    except (ValueError, stripe.SignatureVerificationError):
        return HttpResponse(status=400)
    # handle event['type']
    return HttpResponse(status=200)

Without @csrf_exempt Django returns 403 and the request never reaches your code. On older versions of the library the exception is stripe.error.SignatureVerificationError.

FastAPI

from fastapi import Request, HTTPException

@app.post('/stripe/webhook')
async def stripe_webhook(request: Request):
    payload = await request.body()              # not request.json()
    sig = request.headers.get('stripe-signature')
    try:
        event = stripe.Webhook.construct_event(payload, sig, STRIPE_WEBHOOK_SECRET)
    except (ValueError, stripe.SignatureVerificationError):
        raise HTTPException(status_code=400)
    return {'ok': True}

Do not declare the body as a Pydantic model on this route. FastAPI would parse it and you lose the raw bytes.

Other causes

  • The CLI secret from stripe listen is in production. Use the secret of the live endpoint.
  • A proxy or WAF re-encodes the JSON. Let the webhook path pass through unchanged.
  • The server clock is off. Signatures older than 5 minutes are rejected by default.

After it passes

Return 200 quickly, push slow work to Celery or a background task, and store event['id'] so a retried event is skipped.


If you want this fixed or built in your app, see Stripe webhook or payment bug fix, hire me on Upwork, or get in touch.

Written by Hanzalah Seikhai, Stripe developer. Hire me on Upwork.

More notes