Bird
0
0

Identify the error in this WSGI middleware implementation:

medium📝 Debug Q14 of 15
Flask - Middleware and Extensions
Identify the error in this WSGI middleware implementation:
class BrokenMiddleware:
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        # Forgot to call the wrapped app
        return 'Hello'
AMiddleware must call the wrapped app and return its response
BMiddleware should not have an __init__ method
CMiddleware should return a Flask response object, not a string
DMiddleware must not accept environ and start_response parameters
Step-by-Step Solution
Solution:
  1. Step 1: Check middleware call method

    The __call__ method must call the wrapped app with environ and start_response to get the response.
  2. Step 2: Identify missing call

    This code returns a string directly and does not call the wrapped app, breaking the WSGI chain.
  3. Final Answer:

    Middleware must call the wrapped app and return its response -> Option A
  4. Quick Check:

    Middleware must call wrapped app [OK]
Quick Trick: Middleware must call and return wrapped app response [OK]
Common Mistakes:
MISTAKES
  • Returning a string instead of calling app
  • Removing __init__ method unnecessarily
  • Misunderstanding WSGI call signature

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes