0

Hello i just downloaded an open source Django CRM. Im using VSCode. Installed all the requirements in the dir and inside the venv. When I try to run the server there is a KeyError. These are the final lines that the error comes with: File "C:\Users....\Django-CRM-master\crm\settings.py", line 12, in SECRET_KEY = os.environ["SECRET_KEY"] File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\os.py", line 679, in getitem raise KeyError(key) from None KeyError: 'SECRET_KEY'

From what I can see the Secret_key is in the env file. In settings.py the key is called with SECRET_KEY = os.environ["SECRET_KEY"]. I dont seem to see the problem and I read a ton of fixes today that dont fix it :). Please help.

1 Answers1

1

The error is telling you that the environment variable doesn't exist on your system by saying that the key "SECRET_KEY" is not in the os.environ dictionary-like object which represents all your environment variables.

You'll need to generate a long enough random string, then either set a SECRET_KEY environment variable on your system, or simply replace the use of os.environ['SECRET_KEY'] by this string (not recommended but if you're not using this for testing purposes on your own machine that's fine...)

A fun thread on random string generation: How to generate random strings in Python?

I'm not sure what "env file" you're referring to but you seem to be on Windows so: How to set up environment variables on Windows: Setting Windows PowerShell environment variables

Another thing that might help:

I can see the Secret_key is in the env file

Environment variables are case-sensitive ("Secret_key" != "SECRET_KEY"), so make that sure the key you want to access with os.environ[<key>] and the one in your system are the same.

Clepsyd
  • 496
  • 2
  • 10
  • The size or the kind of the string is not the problem. The system doesnt read anything that has os.environ['.....'] attached to it that is connected to the evn file(the file containing all the environment variables. I managed to get the server running with bypassing the call of the file and just inserting the variables in the fields. But there were still issues and I will look for a different crm project. – Stanislavnba Oct 21 '22 at 20:55
  • I think you misunderstand what environment variables are. They're not variables in a file. They're key/value pairs stored at the operating system level, in your case Windows. `os.environ` stands for OperatingSystem.environment:https://docs.python.org/3/library/os.html#os.environ – Clepsyd Oct 21 '22 at 20:59