Bird
0
0

What is wrong with this FastAPI TrustedHostMiddleware setup? ```python app.add_middleware(TrustedHostMiddleware, allowed_hosts='example.com') ```

medium📝 Debug Q6 of 15
FastAPI - Middleware and Hooks
What is wrong with this FastAPI TrustedHostMiddleware setup? ```python app.add_middleware(TrustedHostMiddleware, allowed_hosts='example.com') ```
Aallowed_hosts must include a port number
BTrustedHostMiddleware cannot be added with add_middleware
CThe middleware requires an additional parameter 'host_check=True'
Dallowed_hosts should be a list, not a string
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter type

    allowed_hosts expects a list of strings.
  2. Step 2: Identify error

    Passing a single string causes a type error or unexpected behavior.
  3. Final Answer:

    allowed_hosts should be a list, not a string -> Option D
  4. Quick Check:

    allowed_hosts must be list [OK]
Quick Trick: allowed_hosts must be a list, not a string [OK]
Common Mistakes:
MISTAKES
  • Passing a single string instead of list
  • Thinking add_middleware is invalid
  • Adding unnecessary parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes