Bird
0
0

Identify the mistake in this Python webhook signature verification code:

medium📝 Debug Q6 of 15
Rest API - Webhooks and Events
Identify the mistake in this Python webhook signature verification code:
import hmac
import hashlib

secret = b'secretkey'
payload = b'webhook payload'
header_signature = 'abcdef123456'

computed_signature = hmac.new(secret, payload, hashlib.sha256).hexdigest

if hmac.compare_digest(computed_signature, header_signature):
    print('Signature valid')
else:
    print('Signature invalid')
ANot encoding payload to bytes
BUsing hashlib.md5 instead of sha256
CComparing bytes with string directly
DMissing parentheses after hexdigest() call
Step-by-Step Solution
Solution:
  1. Step 1: Check hexdigest usage

    hexdigest is a method and must be called with parentheses to get the hex string.
  2. Step 2: Identify error

    In the code, hexdigest is referenced without parentheses, so computed_signature is a method, not a string.
  3. Step 3: Effect

    Passing a method instead of a string to compare_digest causes a TypeError or incorrect comparison.
  4. Final Answer:

    Missing parentheses after hexdigest() call -> Option D
  5. Quick Check:

    hexdigest() requires parentheses to execute [OK]
Quick Trick: Call hexdigest() with parentheses to get string [OK]
Common Mistakes:
MISTAKES
  • Forgetting parentheses on hexdigest()
  • Using wrong hash algorithm
  • Comparing bytes and strings without conversion
  • Not encoding payload to bytes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes