Bird
0
0

Why does this FastAPI app raise an error?

medium📝 Debug Q7 of 15
FastAPI - Dependency Injection
Why does this FastAPI app raise an error?
from fastapi import FastAPI, Depends

app = FastAPI(dependencies=[Depends('not_a_function')])
ADepends cannot be used with FastAPI
BDepends argument must be a callable, not a string
CFastAPI constructor does not accept dependencies
Ddependencies must be empty list
Step-by-Step Solution
Solution:
  1. Step 1: Check Depends argument type

    Depends expects a callable (function), not a string.
  2. Step 2: Identify cause of error

    Passing a string causes a type error because FastAPI tries to call it as a function.
  3. Final Answer:

    Depends argument must be a callable, not a string -> Option B
  4. Quick Check:

    Depends() needs a function, not string [OK]
Quick Trick: Depends() argument must be a function, never a string [OK]
Common Mistakes:
MISTAKES
  • Passing string instead of function to Depends
  • Thinking dependencies must be empty
  • Believing FastAPI constructor disallows dependencies

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes