Predict the output
What does startup print when DATABASE_URL is missing?
import os
def load() -> str:
url = os.environ.get("DATABASE_URL_DEMO_UNSET")
if not url:
raise SystemExit("config error: DATABASE_URL missing")
return url
try:
load()
except SystemExit as e:
print(e)Hint 1 of 1
What does os.environ.get return for a missing key?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A config error: DATABASE_URL missing
Correct. It fails at startup with a clear message.
The app reads config from the environment and refuses to start when a required value is missing. Failing loudly at startup beats failing on the first request with an obscure error.
Why not the others?
- B
None. The function raises before returning. - C A KeyError.
.getreturns None instead of raising. - D Nothing. The SystemExit is caught and printed.