sei-ec-remote / team-project-issues

0 stars 0 forks source link

.env Issue #175

Closed Jlarranaga closed 9 months ago

Jlarranaga commented 9 months ago

Describe the bug A clear and concise description of what the bug is.

Terminal is saying .env file has an keyerror

What is the problem you are trying to solve?

get .en file to work properly

Expected behavior A clear and concise description of what you expected to happen. need to use env file for access to database

What is the actual behavior? A clear and concise description of what actually happened.

Post any code you think might be relevant (one fenced block per file)

Traceback (most recent call last):
  File "/home/jacob/.local/lib/python3.10/site-packages/environ/environ.py", line 388, in get_value
    value = self.ENVIRON[var_name]
  File "/usr/lib/python3.10/os.py", line 680, in __getitem__
    raise KeyError(key) from None
KeyError: 'PASSWORD'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/jacob/sei/django-env/Projects/Project3-DreamHues/Project3DreamHues/manage.py", line 22, in <module>
    main()
  File "/home/jacob/sei/django-env/Projects/Project3-DreamHues/Project3DreamHues/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python3/dist-packages/django/core/management/commands/runserver.py", line 61, in execute
    super().execute(*args, **options)
  File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3/dist-packages/django/core/management/commands/runserver.py", line 68, in handle
    if not settings.DEBUG and not settings.ALLOWED_HOSTS:
  File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/jacob/sei/django-env/Projects/Project3-DreamHues/Project3DreamHues/Project3DreamHues/settings.py", line 86, in <module>
    'PASSWORD': env('PASSWORD'),
  File "/home/jacob/.local/lib/python3.10/site-packages/environ/environ.py", line 199, in __call__
    return self.get_value(
  File "/home/jacob/.local/lib/python3.10/site-packages/environ/environ.py", line 392, in get_value
    raise ImproperlyConfigured(error_msg) from exc
django.core.exceptions.ImproperlyConfigured: Set the PASSWORD environment variable

What is your best guess as to the source of the problem?

Not sure, maybe env file is being read wrong

What things have you already tried to solve the problem?

Team member collab, google

Additional context Add any other context about the problem here.

Paste a link to your repository here https://github.com/Jlarranaga/Project3-DreamHues

nayaba commented 9 months ago

How are you using your environment variables in your settings file?

Jlarranaga commented 9 months ago

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': env('NAME'), 'USER': env('USER'), 'PASSWORD': env('PASSWORD'), 'HOST': env('HOST'), 'PORT': env('PORT'), 'OPTIONS': {'sslmode': 'require'}, } }

Jlarranaga commented 9 months ago

image

Jlarranaga commented 9 months ago

image

nayaba commented 9 months ago

Is this happening on everyone's machine? My first guess is that something is improperly formatted with the PASSWORD value on the env file

Jlarranaga commented 9 months ago

Yeah its everyone's

nayaba commented 9 months ago

Can you get rid of options?

nayaba commented 9 months ago

I'm deleting your last comment so the env info isn't public, but the file looks properly formatted

Jlarranaga commented 9 months ago

Ok thank you, and let me try that

Jlarranaga commented 9 months ago

I commented it out and still didnt work

Jlarranaga commented 9 months ago

image

Jlarranaga commented 9 months ago

For the project I accidently added an extra folder layer. Would that mess with the env file being an extra layer higher?

nayaba commented 9 months ago

It could - the env file needs to be at the same level as manage.py

Jlarranaga commented 9 months ago

Yeah, it's on the same level image

Jlarranaga commented 9 months ago

So I'm reading we need to set the variables. And online it says set the variables in the terminal? But we do that everytime?

nayaba commented 9 months ago

You shouldn't have to do that every time.

Jlarranaga commented 9 months ago

FIXED! .env file needs to be in the same folder as settings.py