python
config_error
ai_generated
true
RuntimeError: The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.
ID: python/flask-secret-key-missing
80%Fix Rate
89%Confidence
0Evidence
2024-01-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Flask's session cookie signing requires app.secret_key, but it was never configured before using session or flash.
generic中文
Flask 的会话 Cookie 签名需要 app.secret_key,但在使用 session 或 flash 之前未配置。
Workarounds
-
95% success
app.config['SECRET_KEY'] = os.environ['SECRET_KEY']
-
90% success
app.secret_key = secrets.token_hex(32) for dev only
Dead Ends
Common approaches that don't work:
-
90% fail
Flask treats empty string as falsy and raises the same error.
-
85% fail
No such option; sessions still require a key.