HBNetwork / python-decouple

Strict separation of config from code.
MIT License
2.83k stars 196 forks source link

decouple.UndefinedValueError: SECRET_KEY not found. #99

Closed dsbyprateekg closed 4 years ago

dsbyprateekg commented 4 years ago

Hi,

I am getting following error-

raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option)) decouple.UndefinedValueError: SECRET_KEY not found. Declare it as envvar or define a default value.

Issue seems with the secret key starting with equal to (=) sign. For example with below secret key: SECRET_KEY = =xg583qt1rc*lec39dy6mtdlg@#v+m0a51no&2@l9fz^nkh&1f

dsbyprateekg commented 4 years ago

I just found my issue. It was not due to equal to sign in secret key. In fact I have given my env file a name but it should be only .env. After changing file from cred.env to .env it is working.

abhishekcaritor commented 2 years ago

add .env file and add this SCOUT_KEY ='' SCOUT_NAME = '' in .env file then pip install scout-apm then Its working

apoorvthedude commented 2 years ago

Hey @dsbyprateekg ,My file name is already .env but still error is coming.

SECRET_KEY = config('SECET_KEY')
File "/opt/venv/lib/python3.8/site-packages/decouple.py", line 243, in __call__
return self.config(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/decouple.py", line 105, in __call__
return self.get(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/decouple.py", line 90, in get
raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: SECET_KEY not found. Declare it as envvar or define a default value.

What to do now

apoorvthedude commented 2 years ago

Hey @abhishekcaritor,I also tried what you said,but still error is coming.

RyanDhingra commented 1 year ago

Has a solution for this been found? I'm having the same issues while trying to deploy my Django API on Pythonanywhere. I've followed the docs word for word and got it setup but am still getting this error.

dakash98 commented 1 year ago

Hi @apoorvthedude, Please check your .env file. I think it's missing.

gentlesoul18 commented 1 year ago

Hi @apoorvthedude, Please check your .env file. I think it's missing.

I am facing this problem and my .env is okay but still getting the error

gentlesoul18 commented 1 year ago

Has a solution for this been found? I'm having the same issues while trying to deploy my Django API on Pythonanywhere. I've followed the docs word for word and got it setup but am still getting this error.

How did you solve this, bro?

RyanDhingra commented 1 year ago

Has a solution for this been found? I'm having the same issues while trying to deploy my Django API on Pythonanywhere. I've followed the docs word for word and got it setup but am still getting this error.

How did you solve this, bro?

Still unsolved, just switched to Flask and deployed via Render.

gentlesoul18 commented 1 year ago

Okay, Thank you

On Wed, Mar 29, 2023 at 4:03 PM Ryan Dhingra @.***> wrote:

Has a solution for this been found? I'm having the same issues while trying to deploy my Django API on Pythonanywhere. I've followed the docs word for word and got it setup but am still getting this error.

How did you solve this, bro?

Still unsolved, just switched to Flask and deployed via Render.

— Reply to this email directly, view it on GitHub https://github.com/HBNetwork/python-decouple/issues/99#issuecomment-1488800049, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR4MROU4MPTRZSSBA2QDXO3W6RFKRANCNFSM4P5YNOYQ . You are receiving this because you commented.Message ID: @.***>

enyfour5 commented 1 year ago

is it possible to create a ".env" file in a dist folder? I keep getting this error and I created the ".env" file in my dist folder but apparently it's not reading it. Any help here is appreciated. I used pyinstaller to create an exe of my python script but keep getting that error. It works outside of my dist folder but not inside my dist folder.

henriquebastos commented 1 year ago

@enyfour5 .env is searched starting on the main module directory going upwards on the directory tree. You can specify a file by:

from decouple import Config, RepositoryEnv

config = Config(RepositoryEnv("path/to/env_file"))
LucasFQuirogaH commented 1 year ago

en settings.py completa la línea como sale debajo: SECRET_KEY = config('SECRET_KEY', default='mydefaultvalue')

Jasur09 commented 1 year ago

def set_token(my_secret): load_dotenv(find_dotenv) TOKEN = os.environ['secret_key']

profermarquez commented 1 year ago

in the program file: SECRET_KEY = config('SECRET_KEY') and in the .env: SECRET_KEY=B!1w8*NAt1T^%kvhUI34g