I am deploying a Flask application on Zeabur, but the app fails to start with the following error:
File "/app/config.py", line 12, in Config
raise ValueError("必须设置环境变量 SECRET_KEY")
ValueError: 必须设置环境变量 SECRET_KEY
Although I have explicitly set the SECRET_KEY environment variable in the service's Environment Variables page, the app does not seem to read it.
Project Details:
- Application type: Python Flask (using Flask-SQLAlchemy)
- Database: MySQL (created inside Zeabur)
- Deployment method: Direct folder upload via "Local Project"
- Code status:
- Modified
config.pyto dynamically build the database connection string using the auto-injectedMYSQL_*variables (following community advice). The manually setDATABASE_URLvariable has been deleted. - Added debug print statements, but the app crashes before executing them.
Steps already taken:
- Verified that
SECRET_KEYexists and has the correct value in the Environment Variables page. - Clicked "Save" and redeployed multiple times – the issue persists.
- Added a debug print in
config.pyright after reading the env var, but the app fails to reach that line. - Deleted and recreated the service several times, re-adding the environment variables each time – still the same error.
Latest logs (relevant part):
Screenshot of environment variables:
(I have attached a screenshot showing that SECRET_KEY is present, with its value redacted for security. The key is correctly set in the environment.))
Questions:
- Why does the app fail to read
SECRET_KEYeven though it appears in the Environment Variables list? - How can I verify whether the environment variable is actually injected into the container?
Additional info:
- I am a paid user (已充值) and would appreciate a quick resolution.
- The project needs to go live as soon as possible. Thank you for your help!