KeyError: 'SECRET_KEY' on Secret Manager

497 views
Skip to first unread message

Valdinia - Office

unread,
Feb 27, 2022, 1:02:55 PM2/27/22
to Google Cloud SQL discuss

I want to run a Django application on the App Engine flexible environment.
I follow the documentation step by step (https://cloud.google.com/python/django/flexible-environment).

For the Django sample app, on Cloud SQL I'm using PostgreSQL

I store the secret values (Django settings) in Secret Manager, (https://cloud.google.com/python/django/flexible-environment#store-secret-values-in-secret-manager)

Now with the backing services configured, I try to run the sample app on my computer (I mean the sample app provided by the documentation https://cloud.google.com/python/django/flexible-environment#clone_a_sample_app)

At step 4, "Run the Django migrations to set up your models and assets" when I run the  "python manage.py makemigrations" command I get a series of errors:

File "C:\Users\zzz\AppData\Local\Programs\Python\Python39\lib\site-packages\environ\environ.py", line 367, in get_value
    value = self.ENVIRON[var]
  File "C:\Users\zzz\AppData\Local\Programs\Python\Python39\lib\os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'SECRET_KEY'

During handling of the above exception, another exception occurred:
....
File "C:\Users\zzz\AppData\Local\Programs\Python\Python39\lib\site-packages\environ\environ.py", line 371, in get_value
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable

What could be the cause? I followed the documentation step by step.

Of course, on the code samples I edited the db name, the db password, project ID, region, instance name, bucket name etc

Thank you!
Valdinia





George (Cloud Platform Support)

unread,
Feb 28, 2022, 11:16:04 AM2/28/22
to Google Cloud SQL discuss
Hello, 

The documentation you followed guides towards setting up authentication in a Flexible environment. You need to run the app locally, so you should follow Run the app on your local computer

This discussion group is oriented more towards general opinions, trends, and issues of general nature touching the App Engine. For coding and program architecture, as well as setting up local authentication, you may be better served in dedicated forums such as stackoverflow, where experienced programmers are within reach and ready to help. 

Reply all
Reply to author
Forward
0 new messages