Comments (11)
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.
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.
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.
Any news for this problem - it blocks most of out project for update this package
from django-environ.
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.
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.
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.
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.
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:
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.
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:
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.pyBoth 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.
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)
- Environment variables' reimports not supported HOT 1
- Officially support Django 4.2 and Python 3.12 on PyPI HOT 1
- Ask for next release HOT 1
- v0.11.0 Introduces parsing error for strings containing more than one $ symbol HOT 6
- v0.11.1: $-symbol issue HOT 5
- v0.11.0/ v0.11.1 breaks on Mac OSX HOT 1
- UserWarning: Engine not recognized from url : sqlite3 HOT 3
- Simplicity and Stability vs Advanced Features HOT 2
- Hash sign inside double quotes is interpreted as the start of a comment HOT 5
- Deprecated Code from python 2.x to 3.x HOT 1
- db_url() fail with oracle dsn
- db support for CockroachDB HOT 1
- Wrong missing environment variable name if using prefix HOT 1
- Django's RedisCache OPTIONS needs to be lowercase
- Double quotes no longer work for including the `#` in a string HOT 5
- ModuleNotFoundError: No module named 'environ'
- Support new db option `pool` in Django 5.1
- Restore defaults in .env HOT 6
- DeprecationWarning: 'pkgutil.find_loader' is deprecated and slated for removal in Python 3.14; use importlib.util.find_spec() instead on 3.12 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-environ.