Sam B
Sam B

Reputation: 187

Set Python Flask Secret Key in Windows

I am working on a Python Flask Web App in Windows, and I cannot set my secret key as an environment variable. I have set it through PowerShell and Windows GUI. I have also tried using Git Bash to set it. I can successfully set and return the environment variable in all instances.

In my Flask config, I have:

SECRET_KEY = os.environ.get("MY_SECRET_KEY", "")

I get this error:

RuntimeError: the session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.

If I hard code the secret key, it works fine. I understand there might be the question of why I want to set the secret key as an environment variable, and my current assumption is I want to know what it is, and I don't want it in the code.

I'm open to any thoughts and suggestions. Thanks.

Upvotes: 0

Views: 1184

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 113940

C:\py_exp>set MY_VAR=123

C:\py_exp>echo %MY_VAR%
123

C:\py_exp>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print os.environ["MY_VAR"]
123

not much of an answer but best I can do for you given the question

Upvotes: 2

Related Questions