Interview Prep/Python for DevOps/Concurrency, async, tests, services & containers

GitHub webhook signature verification fails for every request, though the secret is correct.

IntermediateTroubleshootingConcurrency, async, tests, services & containers
Answer

Likely causes → The HMAC is computed over re-serialized JSON (json.dumps(request.json)) instead of the raw body bytes, or the secret has trailing whitespace/newline from the secret store, or comparing against X-Hub-Signature (SHA-1) instead of X-Hub-Signature-256.

Diagnose → Log lengths (never values) of the secret and body; compare computed vs received prefix.

Fix → Use request.get_data() (Flask) or await request.body() (FastAPI) for the HMAC, .strip() the secret, and compare "sha256=" + hexdigest with hmac.compare_digest.

Prevent → Unit test the verifier with a known payload, secret and signature.

All Python for DevOps questions Roadmap: Python for automation

More on Concurrency, async, tests, services & containers