Bird
0
0

You wrote this code:

medium📝 Debug Q6 of 15
Flask - Deployment
You wrote this code:
import os
secret_key = os.getenv('SECRET_KEY')
print(secret_key)

But it always prints None even though you set the environment variable. What is the likely problem?
AYou must use os.environ['SECRET_KEY'] instead
Bos.getenv cannot read environment variables
CSECRET_KEY is a reserved Flask variable
DThe environment variable was not exported in the shell
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment variable visibility

    Environment variables must be exported in the shell to be visible to Python processes.
  2. Step 2: Check other options for correctness

    os.getenv can read env vars; SECRET_KEY is not reserved; os.environ[] raises error if missing, not safer.
  3. Final Answer:

    The environment variable was not exported in the shell -> Option D
  4. Quick Check:

    Env vars must be exported to be read [OK]
Quick Trick: Export env vars in shell before running Flask app [OK]
Common Mistakes:
MISTAKES
  • Thinking os.getenv is broken
  • Believing SECRET_KEY is reserved
  • Using os.environ[] without checking existence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes