theskumar / python-dotenv

Reads key-value pairs from a .env file and can set them as environment variables. It helps in developing applications following the 12-factor principles.
https://saurabh-kumar.com/python-dotenv/
BSD 3-Clause "New" or "Revised" License
7.46k stars 423 forks source link

just doesn't work in mod_wsgi #375

Open awhileback opened 2 years ago

awhileback commented 2 years ago
(.local) user@NAS ~/django $ python manage.py shell
Python 3.8.10 (default, Nov 26 2021, 20:14:08) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import os
>>> from dotenv import load_dotenv
>>> load_dotenv()
True
>>> os.environ.get('DOTIME_ZONES')
'US/Eastern,US/Central,US/Mountain,US/Arizona,US/Pacific,US/Hawaii,UTC'
>>> quit()(
... 
... 
KeyboardInterrupt
>>> quit()
(.local) user@NAS ~/django $ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
February 09, 2022 - 03:11:53
Django version 3.2.12, using settings 'website.settings.prod'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[Wed Feb 09 09:12:45.664253 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Wed Feb 09 09:12:45.664292 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[Wed Feb 09 09:12:45.664321 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]     return _bootstrap._gcd_import(name[level:], package, level)
[Wed Feb 09 09:12:45.664358 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Wed Feb 09 09:12:45.664398 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Wed Feb 09 09:12:45.664437 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
[Wed Feb 09 09:12:45.664477 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
[Wed Feb 09 09:12:45.664516 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "<frozen importlib._bootstrap_external>", line 848, in exec_module
[Wed Feb 09 09:12:45.664556 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Wed Feb 09 09:12:45.664596 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "/user/django/website/settings/prod.py", line 1, in <module>
[Wed Feb 09 09:12:45.664625 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]     from .base import *
[Wed Feb 09 09:12:45.664662 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]   File "/user/django/website/settings/base.py", line 141, in <module>
[Wed Feb 09 09:12:45.664692 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972]     WAGTAIL_USER_TIME_ZONES = os.environ.get('DOTIME_ZONES').split(',')
[Wed Feb 09 09:12:45.664752 2022] [wsgi:error] [pid 609129:tid 139894886209280] [client 127.0.0.1:41972] AttributeError: 'NoneType' object has no attribute 'split'

(.local) user@NAS ~/django $ pip freeze | grep dotenv python-dotenv==0.19.2

theskumar commented 2 years ago

@awhileback Can you share the code where you are loading the .env file in your Django code?