Giter Club home page Giter Club logo

Comments (11)

hannylicious avatar hannylicious commented on June 22, 2024 2

I can confirm this occurs with 11.0, 11.1 and 11.2.

I'll see if I can write some tests that show the cases where it's an issue (essentially it's any SECRET_KEY that has a hashtag in it that is not surrounded in quotes)

from django-environ.

mindcruzer avatar mindcruzer commented on June 22, 2024 1

I'm surprised that it's been over a month and this hasn't been fixed. My CI tests caught this error and it took me about 30 mins to figure out that it was because there was a # character at the start of my production SECRET_KEY. My app secrets are read from a file, and putting the SECRET_KEY in quotes did not solve the problem. Downgrading to 0.10.0 was the only way to get around this as changing the SECRET_KEY value will kill all existing sessions.

from django-environ.

amstilp avatar amstilp commented on June 22, 2024 1

I'm running into this issue as well with a secret key that has a # character in it. It is stored a file; putting quotes around it did not help.

from django-environ.

dk-WZFinTech avatar dk-WZFinTech commented on June 22, 2024 1

Any news for this problem - it blocks most of out project for update this package

from django-environ.

hannylicious avatar hannylicious commented on June 22, 2024

Additional note: if I change DJANGO_SECRET_KEY to SECRET_KEY in my .env file the application will work... but seeing as I have this line:

SECRET_KEY = env.str("DJANGO_SECRET_KEY")

in my settings/base.py and it had always worked prior, I'm a little confused as to why it now has to be explicitly named in the .env file and isn't being read in the settings as it had been prior.

from django-environ.

hannylicious avatar hannylicious commented on June 22, 2024

The issue has to do with the SECRET_KEY value itself and how it's being read by django-environ.

Hashtags (#) are a naturally occurring element in Django secret keys: however for some reason when django-environ comes across them it is not reading anything beyond the hashtag.

I'm not sure the best way to fix this - but I'll keep digging. For anyone else at this time - just make sure there are no hashtags in your SECRET_KEY and you should be fine.

from django-environ.

hannylicious avatar hannylicious commented on June 22, 2024

So, after digging around in the code I realized that I could wrap my secret key in quotes and it would render appropriately.

However, it didn't used to be this way and in the documentation it doesn't show wrapping the secret key in quotes.

SECRET_KEY=your-secret-key (from the docs)

But a temporary workaround is:

SECRET_KEY="your-secret-key"

from django-environ.

sergeyklay avatar sergeyklay commented on June 22, 2024

Hello @hannylicious,

Thank you for bringing this issue to our attention. We are currently investigating several issues related to environment variable parsing, especially concerning the SECRET_KEY.

Could you please try using the latest version and see if the issue persists? If it does, consider rolling back to version 0.10.0 as a temporary workaround.

Your input is invaluable as we try to get to the bottom of this. It seems a few things have slipped through the cracks in our codebase that require immediate attention.

Best regards,

from django-environ.

hong539 avatar hong539 commented on June 22, 2024

Hello, every body, I think I got the similar issue when I want to using django-environ for My little django app.
And here is My github repo link:
local_library_website

And My django environment is setup with pyenv+poetry on my Arch Linux VM.
pyenv to lock My python interpreter and verion == 3.8.16
poetry to manage My project denpendency and also the version info is Poetry (version 1.5.1)
dependency details will be included in these files, and there are the links:

pyproject.toml
poetry.lock

And I've tried django-environ versions 0.11.2/0.10.0 with this little command
Also here is my codes for settings.py
And .env file is here .env.test

python3 settings.py

Both verions of django-environ give me the messages:

Traceback (most recent call last):
  File "/home/hong/.cache/pypoetry/virtualenvs/local-library-website-nGKGTRaN-py3.8/lib/python3.8/site-packages/environ/environ.py", line 387, in get_value
    value = self.ENVIRON[var_name]
  File "/home/hong/.pyenv/versions/3.8.16/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'SECRET_KEY'

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

Traceback (most recent call last):
  File "settings.py", line 33, in <module>
    SECRET_KEY = env('SECRET_KEY')
  File "/home/hong/.cache/pypoetry/virtualenvs/local-library-website-nGKGTRaN-py3.8/lib/python3.8/site-packages/environ/environ.py", line 198, in __call__
    return self.get_value(
  File "/home/hong/.cache/pypoetry/virtualenvs/local-library-website-nGKGTRaN-py3.8/lib/python3.8/site-packages/environ/environ.py", line 391, in get_value
    raise ImproperlyConfigured(error_msg) from exc
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable

And how should I do next step? Any guides/tips? Thanks a lot!

from django-environ.

hong539 avatar hong539 commented on June 22, 2024

Hello, every body, I think I got the similar issue when I want to using django-environ for My little django app. And here is My github repo link: local_library_website

And My django environment is setup with pyenv+poetry on my Arch Linux VM. pyenv to lock My python interpreter and verion == 3.8.16 poetry to manage My project denpendency and also the version info is Poetry (version 1.5.1) dependency details will be included in these files, and there are the links:

pyproject.toml poetry.lock

And I've tried django-environ versions 0.11.2/0.10.0 with this little command Also here is my codes for settings.py And .env file is here .env.test

python3 settings.py

Both verions of django-environ give me the messages:

Traceback (most recent call last):
  File "/home/hong/.cache/pypoetry/virtualenvs/local-library-website-nGKGTRaN-py3.8/lib/python3.8/site-packages/environ/environ.py", line 387, in get_value
    value = self.ENVIRON[var_name]
  File "/home/hong/.pyenv/versions/3.8.16/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'SECRET_KEY'

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

Traceback (most recent call last):
  File "settings.py", line 33, in <module>
    SECRET_KEY = env('SECRET_KEY')
  File "/home/hong/.cache/pypoetry/virtualenvs/local-library-website-nGKGTRaN-py3.8/lib/python3.8/site-packages/environ/environ.py", line 198, in __call__
    return self.get_value(
  File "/home/hong/.cache/pypoetry/virtualenvs/local-library-website-nGKGTRaN-py3.8/lib/python3.8/site-packages/environ/environ.py", line 391, in get_value
    raise ImproperlyConfigured(error_msg) from exc
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable

And how should I do next step? Any guides/tips? Thanks a lot!

Oh...Sorry I think I have to settinup the right PATH for BASE_DIR... to actually find out where is ".env.test" files. XD

from django-environ.

amstilp avatar amstilp commented on June 22, 2024

Hi @sergeyklay I put together a repo containing a reproducible example of the bug as I'm seeing it! Hope this helps.

https://github.com/amstilp/django-environ-issue-497

from django-environ.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.