Issue with WSGI and Django 1.8 - python

Please help to understand what is going on.
I have a project in Django. It's working correctly without WSGI (I mean via manage.py), but when I move to WSGI I got the problems.
There is httpd error logs :
[Mon May 02 16:58:23.316772 2016] [ssl:info] [pid 16850] [client IP:29158] AH01964: Connection to child 1 established (server server:443)
[Mon May 02 16:58:23.352418 2016] [socache_shmcb:debug] [pid 16850] mod_socache_shmcb.c(485): AH00831: socache_shmcb_store (0x81 -> subcache 1)
[Mon May 02 16:58:23.352488 2016] [socache_shmcb:debug] [pid 16850] mod_socache_shmcb.c(810): AH00847: insert happened at idx=0, data=(0:32)
[Mon May 02 16:58:23.352500 2016] [socache_shmcb:debug] [pid 16850] mod_socache_shmcb.c(815): AH00848: finished insert, subcache: idx_pos/idx_used=0/1, data_pos/data_used=0/180
[Mon May 02 16:58:23.352542 2016] [socache_shmcb:debug] [pid 16850] mod_socache_shmcb.c(506): AH00834: leaving socache_shmcb_store successfully
[Mon May 02 16:58:23.352600 2016] [ssl:debug] [pid 16850] ssl_engine_kernel.c(1812): [client IP:29158] AH02041: Protocol: TLSv1, Cipher: RC4-SHA (128/128 bits)
[Mon May 02 16:58:23.370771 2016] [ssl:debug] [pid 16850] ssl_engine_kernel.c(224): [client IP:29158] AH02034: Initial (No.1) HTTPS request received for child 1 (server server:443)
[Mon May 02 16:58:23.371004 2016] [authz_core:debug] [pid 16850] mod_authz_core.c(809): [client IP:29158] AH01626: authorization result of Require all granted: granted
[Mon May 02 16:58:23.371015 2016] [authz_core:debug] [pid 16850] mod_authz_core.c(809): [client IP:29158] AH01626: authorization result of <RequireAny>: granted
[Mon May 02 16:58:23.371202 2016] [authz_core:debug] [pid 16850] mod_authz_core.c(809): [client IP:29158] AH01626: authorization result of Require all granted: granted
[Mon May 02 16:58:23.371211 2016] [authz_core:debug] [pid 16850] mod_authz_core.c(809): [client IP:29158] AH01626: authorization result of <RequireAny>: granted
[Mon May 02 16:58:23.371650 2016] [:info] [pid 16839] [remote IP] mod_wsgi (pid=16839, process='project', application=''): Loading WSGI script '/usr/local/env/project/apache/project.wsgi'.
[Mon May 02 16:58:23.849532 2016] [:error] [pid 16839] [remote IP] mod_wsgi (pid=16839): Target WSGI script '/usr/local/env/project/apache/project.wsgi' cannot be loaded as Python module.
[Mon May 02 16:58:23.849596 2016] [:error] [pid 16839] [remote IP] mod_wsgi (pid=16839): Exception occurred processing WSGI script '/usr/local/env/project/apache/project.wsgi'.
[Mon May 02 16:58:23.849636 2016] [:error] [pid 16839] [remote IP] Traceback (most recent call last):
[Mon May 02 16:58:23.849671 2016] [:error] [pid 16839] [remote IP] File "/usr/local/env/project/apache/project.wsgi", line 13, in <module>
[Mon May 02 16:58:23.849742 2016] [:error] [pid 16839] [remote IP] application = get_wsgi_application()
[Mon May 02 16:58:23.849775 2016] [:error] [pid 16839] [remote IP] File "/usr/local/env/project_django18/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Mon May 02 16:58:23.849832 2016] [:error] [pid 16839] [remote IP] django.setup()
[Mon May 02 16:58:23.849850 2016] [:error] [pid 16839] [remote IP] File "/usr/local/env/project_django18/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
[Mon May 02 16:58:23.849900 2016] [:error] [pid 16839] [remote IP] apps.populate(settings.INSTALLED_APPS)
[Mon May 02 16:58:23.849920 2016] [:error] [pid 16839] [remote IP] File "/usr/local/env/project_django18/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
[Mon May 02 16:58:23.850096 2016] [:error] [pid 16839] [remote IP] app_config.import_models(all_models)
[Mon May 02 16:58:23.850125 2016] [:error] [pid 16839] [remote IP] File "/usr/local/env/project_django18/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
[Mon May 02 16:58:23.850224 2016] [:error] [pid 16839] [remote IP] self.models_module = import_module(models_module_name)
[Mon May 02 16:58:23.850246 2016] [:error] [pid 16839] [remote IP] File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Mon May 02 16:58:23.850303 2016] [:error] [pid 16839] [remote IP] __import__(name)
[Mon May 02 16:58:23.850324 2016] [:error] [pid 16839] [remote IP] File "/usr/local/env/project/config/models.py", line 10, in <module>
[Mon May 02 16:58:23.851120 2016] [:error] [pid 16839] [remote IP] from webui.models import Change
[Mon May 02 16:58:23.851181 2016] [:error] [pid 16839] [remote IP] ImportError: No module named models
[Mon May 02 16:58:23.851589 2016] [ssl:debug] [pid 16850] ssl_engine_io.c(992): [client IP:29158] AH02001: Connection closed to child 1 with standard shutdown (server server:443)
Why WSGI can't import it?
There is my wsgi.conf
#!/usr/local/env/project_django18/bin/python
import os
import sys
sys.path.append('/usr/local/env/project/')
import project
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
activate_this = os.path.expanduser("/usr/local/env/project_django18/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
P.S. webui it's just application of Django. And Change is one of models of it.
P.S.S. If need additional information please give me know

Related

Importing Flask application to Elastic Beanstalk error: can't open file 'mod_wsgi': [Errno 2] No such file or directory

I am attempting to put my Flask application on Elastic Beanstalk (Amazon Web Services, EC2), but after uploading the files I receive a 500 error. Any thoughts on what could be the issue? The error log:
/opt/python/run/venv/bin/python3: can't open file 'mod_wsgi': [Errno 2] No such file or directory
[Fri Sep 08 03:23:05.754341 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] mod_wsgi (pid=13619): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
[Fri Sep 08 03:23:05.754577 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] mod_wsgi (pid=13619): SystemExit exception raised by WSGI script '/opt/python/current/app/application.py' ignored.
[Fri Sep 08 03:23:05.754729 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] Traceback (most recent call last):
[Fri Sep 08 03:23:05.754992 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] File "/opt/python/current/app/application.py", line 11, in <module>
[Fri Sep 08 03:23:05.755007 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] application.run(debug=True)
[Fri Sep 08 03:23:05.755116 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 772, in run
[Fri Sep 08 03:23:05.755131 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] run_simple(host, port, self, **options)
[Fri Sep 08 03:23:05.755242 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] File "/opt/python/run/venv/lib/python3.4/site-packages/werkzeug/serving.py", line 737, in run_simple
[Fri Sep 08 03:23:05.755257 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] reloader_type)
[Fri Sep 08 03:23:05.755344 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] File "/opt/python/run/venv/lib/python3.4/site-packages/werkzeug/_reloader.py", line 265, in run_with_reloader
[Fri Sep 08 03:23:05.755358 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] sys.exit(reloader.restart_with_reloader())
[Fri Sep 08 03:23:05.755429 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] SystemExit: 2
My file structure is as follows:
file hierarchy
My WSGI path is
config
Turns out I needed to wrap application.run() within a if __name__ == '__main__': block. This ensures that a local WSGI server is not loaded by default.
Source: http://flask.pocoo.org/docs/0.11/deploying/mod_wsgi/

ImproperlyConfigured: The SECRET_KEY setting must not be empty in Apache and wsgi_mod

I'm trying to deploy Django project on Apache and wsgi_mod in Windows 10. What I did so far:
1. Added following in httpd.conf of Apache conf folder
WSGIScriptAlias / "C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn/wsgi.py"
WSGIPythonPath "C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project;C:/Bitnami/djangostack-1.10.1-0/python/Lib/site-packages"
<Directory "C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
2. Following is the content of my wsgi.py file:
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "egeirn.settings")
application = get_wsgi_application()
When I start the Apache server, it gives the following error in logs file:
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] mod_wsgi (pid=916): Target WSGI script 'C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn/wsgi.py' cannot be loaded as Python module., referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] mod_wsgi (pid=916): Exception occurred processing WSGI script 'C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn/wsgi.py'., referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] Traceback (most recent call last):, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:/Bitnami/djangostack-1.10.1-0/apps/django/django_projects/project/egeirn/wsgi.py", line 18, in <module>, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] application = get_wsgi_application(), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\core\\wsgi.py", line 13, in get_wsgi_application, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] django.setup(set_prefix=False), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\__init__.py", line 22, in setup, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\conf\\__init__.py", line 53, in __getattr__, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] self._setup(name), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\conf\\__init__.py", line 41, in _setup, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] self._wrapped = Settings(settings_module), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] File "C:\\Bitnami\\djangostack-1.10.1-0\\apps\\django\\django-1.10.1-py2.7.egg\\django\\conf\\__init__.py", line 116, in __init__, referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] raise ImproperlyConfigured("The SECRET_KEY setting must not be empty."), referer: http://localhost:82/
[Thu Nov 03 17:47:11.328063 2016] [:error] [pid 916:tid 1236] [client ::1:63236] ImproperlyConfigured: The SECRET_KEY setting must not be empty., referer: http://localhost:82/
I am using django-environ to read .env file and keep configurations in environment variables. Although I have my SECRET_KEY in the base.py file
I have used it like this in base.py file:
import environ
# three folder back (/project/egeirn/settings/ - 3 = /)
root = environ.Path(__file__) - 3
# set default values and casting
env = environ.Env(DEBUG=(bool, False),)
# reading .env file
environ.Env.read_env(os.path.join(BASE_DIR, '../../config/.env'))
SITE_ROOT = root()
# Raises ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')
This is my .env file:
SECRET_KEY=<MY_SECRET_KEY_HERE>
Please tell me what I am doing wrong here, how come it cannot read the SECRET_KEY?
Thanks

Error 500 using apache 2.4: django ImportError: No module named 'myproject'

I am using Apache 2.4 with python 3.4 and corresponding version of mod_wsgi on a windows 2012 R2 server machine. All 64 bits. Right now after starting apache, I have this problem:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at admin#example.com to inform
them of the time this error occurred, and the actions you performed
just before this error.
More information about this error may be available in the server error
log.
So when going through the error log, I found those relevant lines (logging in debug mode):
The 'Apache2.4' service is restarting.
[Wed Oct 05 12:06:08.561983 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00424: Parent: Received restart signal -- Restarting the server.
[Wed Oct 05 12:06:08.561983 2016] [mpm_winnt:debug] [pid 10092:tid 456] child.c(1157): AH00357: Child: Exit event signaled. Child process is ending.
[Wed Oct 05 12:06:08.561983 2016] [mpm_winnt:debug] [pid 10092:tid 1000] child.c(735): AH00348: Child: Accept thread exiting.
[Wed Oct 05 12:06:08.561983 2016] [mpm_winnt:debug] [pid 10092:tid 996] child.c(735): AH00348: Child: Accept thread exiting.
[Wed Oct 05 12:06:08.577609 2016] [wsgi:warn] [pid 7756:tid 528] mod_wsgi: Compiled for Python/3.4.2.
[Wed Oct 05 12:06:08.577609 2016] [wsgi:warn] [pid 7756:tid 528] mod_wsgi: Runtime using Python/3.4.3.
[Wed Oct 05 12:06:08.577609 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00455: Apache/2.4.23 (Win64) mod_wsgi/4.4.12 Python/3.4.3 configured -- resuming normal operations
[Wed Oct 05 12:06:08.577609 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00456: Apache Lounge VC10 Server built: Jul 9 2016 11:59:00
[Wed Oct 05 12:06:08.577609 2016] [core:notice] [pid 7756:tid 528] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'
[Wed Oct 05 12:06:08.577609 2016] [core:debug] [pid 7756:tid 528] log.c(1543): AH02639: Using SO_REUSEPORT: no (0)
[Wed Oct 05 12:06:08.577609 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00418: Parent: Created child process 10576
[Wed Oct 05 12:06:08.577609 2016] [mpm_winnt:debug] [pid 7756:tid 528] mpm_winnt.c(429): AH00402: Parent: Sent the scoreboard to the child
[Wed Oct 05 12:06:08.905752 2016] [wsgi:warn] [pid 10576:tid 456] mod_wsgi: Compiled for Python/3.4.2.
[Wed Oct 05 12:06:08.905752 2016] [wsgi:warn] [pid 10576:tid 456] mod_wsgi: Runtime using Python/3.4.3.
[Wed Oct 05 12:06:08.905752 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(1718): AH00453: Child process is running
[Wed Oct 05 12:06:08.905752 2016] [wsgi:info] [pid 10576:tid 456] mod_wsgi (pid=10576): Initializing Python.
[Wed Oct 05 12:06:08.952607 2016] [wsgi:info] [pid 10576:tid 456] mod_wsgi (pid=10576): Attach interpreter ''.
[Wed Oct 05 12:06:08.952607 2016] [wsgi:info] [pid 10576:tid 456] mod_wsgi (pid=10576): Adding '\xe2\x80\x9cC:/Apache24/htdocs/EquipmentCalibration\xe2\x80\x9d' to path.
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(343): AH00391: Child: Retrieved our scoreboard from the parent.
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(465): AH00403: Child: Waiting for data for listening socket 0.0.0.0:8090
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 7756:tid 528] mpm_winnt.c(512): AH00408: Parent: Duplicating socket 500 (0.0.0.0:8090) and sending it to child process 10576
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 7756:tid 528] mpm_winnt.c(512): AH00408: Parent: Duplicating socket 540 ([::]:8090) and sending it to child process 10576
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 7756:tid 528] mpm_winnt.c(531): AH00411: Parent: Sent 2 listeners to child 10576
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(465): AH00403: Child: Waiting for data for listening socket [::]:8090
[Wed Oct 05 12:06:08.952607 2016] [mpm_winnt:debug] [pid 10576:tid 456] mpm_winnt.c(490): AH00407: Child: retrieved 2 listeners from parent
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10092:tid 456] child.c(1214): AH00359: Child: Released the start mutex
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10576:tid 456] child.c(1020): AH00352: Child: Acquired the start mutex.
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10092:tid 456] child.c(1226): AH00361: Child: 64 threads blocked on the completion port
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:notice] [pid 10576:tid 456] AH00354: Child: Starting 64 worker threads.
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10576:tid 872] child.c(399): AH00334: Child: Accept thread listening on 0.0.0.0:8090 using AcceptFilter data
[Wed Oct 05 12:06:09.577635 2016] [mpm_winnt:debug] [pid 10576:tid 876] child.c(399): AH00334: Child: Accept thread listening on [::]:8090 using AcceptFilter data
[Wed Oct 05 12:06:10.581491 2016] [mpm_winnt:notice] [pid 10092:tid 456] AH00364: Child: All worker threads have exited.
[Wed Oct 05 12:06:10.581491 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Destroying interpreters.
[Wed Oct 05 12:06:10.581491 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Destroy interpreter 'PCTEST-IIS.pctestlab.com:8090|'.
[Wed Oct 05 12:06:10.581491 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): End interpreter 'PCTEST-IIS.pctestlab.com:8090|'.
[Wed Oct 05 12:06:10.612772 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Cleanup interpreter ''.
[Wed Oct 05 12:06:10.644022 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Terminating Python.
[Wed Oct 05 12:06:10.659650 2016] [wsgi:info] [pid 10092:tid 456] mod_wsgi (pid=10092): Python has shutdown.
[Wed Oct 05 12:06:10.659650 2016] [mpm_winnt:debug] [pid 10092:tid 456] mpm_winnt.c(1723): AH00454: Child process is exiting
[Wed Oct 05 12:06:13.971571 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61169] AH01626: authorization result of Require all granted: granted
[Wed Oct 05 12:06:13.971571 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61169] AH01626: authorization result of <RequireAny>: granted
[Wed Oct 05 12:06:13.971571 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61169] AH01626: authorization result of Require all granted: granted
[Wed Oct 05 12:06:13.971571 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61169] AH01626: authorization result of <RequireAny>: granted
[Wed Oct 05 12:06:14.019608 2016] [wsgi:info] [pid 10576:tid 1116] mod_wsgi (pid=10576): Create interpreter 'PCTEST-IIS.pctestlab.com:8090|'.
[Wed Oct 05 12:06:14.050609 2016] [wsgi:info] [pid 10576:tid 1116] mod_wsgi (pid=10576): Adding '\xe2\x80\x9cC:/Apache24/htdocs/EquipmentCalibration\xe2\x80\x9d' to path.
[Wed Oct 05 12:06:14.053609 2016] [wsgi:info] [pid 10576:tid 1116] [client ::1:61169] mod_wsgi (pid=10576, process='', application='PCTEST-IIS.pctestlab.com:8090|'): Loading WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py'.
[Wed Oct 05 12:06:14.660623 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] mod_wsgi (pid=10576): Target WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py' cannot be loaded as Python module.
[Wed Oct 05 12:06:14.660623 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] mod_wsgi (pid=10576): Exception occurred processing WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py'.
[Wed Oct 05 12:06:14.660623 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] Traceback (most recent call last):\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:/EquipmentCalibration/equipcal/wsgi.py", line 16, in <module>\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] application = get_wsgi_application()\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\core\\wsgi.py", line 13, in get_wsgi_application\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] django.setup(set_prefix=False)\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\__init__.py", line 22, in setup\r
[Wed Oct 05 12:06:14.661628 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 53, in __getattr__\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] self._setup(name)\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 41, in _setup\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] self._wrapped = Settings(settings_module)\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 97, in __init__\r
[Wed Oct 05 12:06:14.662625 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "C:\\Python34\\Lib\\importlib\\__init__.py", line 109, in import_module\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] return _bootstrap._gcd_import(name[level:], package, level)\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked\r
[Wed Oct 05 12:06:14.663602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61169] ImportError: No module named 'equipcal'\r
[Wed Oct 05 12:06:14.678602 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61170] AH01626: authorization result of Require all granted: granted, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.678602 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61170] AH01626: authorization result of <RequireAny>: granted, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.679602 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61170] AH01626: authorization result of Require all granted: granted, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.679602 2016] [authz_core:debug] [pid 10576:tid 1116] mod_authz_core.c(806): [client ::1:61170] AH01626: authorization result of <RequireAny>: granted, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.679602 2016] [wsgi:info] [pid 10576:tid 1116] [client ::1:61170] mod_wsgi (pid=10576, process='', application='PCTEST-IIS.pctestlab.com:8090|'): Loading WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py'., referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.681602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] mod_wsgi (pid=10576): Target WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py' cannot be loaded as Python module., referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.681602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] mod_wsgi (pid=10576): Exception occurred processing WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py'., referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] Traceback (most recent call last):\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:/EquipmentCalibration/equipcal/wsgi.py", line 16, in <module>\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] application = get_wsgi_application()\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\core\\wsgi.py", line 13, in get_wsgi_application\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] django.setup(set_prefix=False)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\__init__.py", line 22, in setup\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 53, in __getattr__\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.682602 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] self._setup(name)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 41, in _setup\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] self._wrapped = Settings(settings_module)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\lib\\site-packages\\django\\conf\\__init__.py", line 97, in __init__\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] mod = importlib.import_module(self.SETTINGS_MODULE)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "C:\\Python34\\Lib\\importlib\\__init__.py", line 109, in import_module\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] return _bootstrap._gcd_import(name[level:], package, level)\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked\r, referer: http://localhost:8090/calbase/static
[Wed Oct 05 12:06:14.683601 2016] [wsgi:error] [pid 10576:tid 1116] [client ::1:61170] ImportError: No module named 'equipcal'\r, referer: http://localhost:8090/calbase/static
Apparently it looks like the problem is this:
Target WSGI script 'C:/EquipmentCalibration/equipcal/wsgi.py' cannot be loaded as Python module.
and:
ImportError: No module named 'equipcal'\r,
Where equipcal is my project name.
But this seems really weird, how could wsgi not loaded as python and my proejct not recognized? Especially I tried to add project directory into wsgi. My wsgi.py looks like this:
"""
WSGI config for equipcal project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
from django.core.wsgi import get_wsgi_application
import os, sys
sys.path.append('C:\Apache24\htdocs\EquipmentCalibration\equipcal')
sys.path.append('C:\Apache24\htdocs\EquipmentCalibration')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "equipcal.settings")
application = get_wsgi_application()
And in httpd.conf:
DocumentRoot "c:/Apache24/htdocs"
# Change Python path used by the server.
WSGIPythonPath “/EquipmentCalibration”
# Make calls to http://localhost/ refer to the Python/WSGI-script located at the specified location.
WSGIScriptAlias / /EquipmentCalibration/equipcal/wsgi.py
# Make calls to http://localhost/static refer to the specified folder.
Alias /static/ /EquipmentCalibration/static
Alias /media/ /EquipmentCalibration/media
<Directory /EquipmentCalibration/static>
Require all granted
</Directory>
<Directory /EquipmentCalibration/media>
Require all granted
</Directory>
<Directory /EquipmentCalibration/equipcal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
my project is located as c:/Apache24/htdocs/EquipmentCalibration with project named equipcal.
With helps I figured out most other problem but got really stuck on this one. Could somebody please help me out?
Do I need something like a wsgi_handler.py?

AWS mod_wsgi error when deploying Flask with elasticbeanstalk

Getting the following error with flask on elasticbeanstalk:
/opt/python/run/venv/bin/python3: can't open file 'mod_wsgi': [Errno 2] No such file or directory
[Sat Aug 08 23:43:35.994357 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] mod_wsgi (pid=7748): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
[Sat Aug 08 23:43:35.994407 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] mod_wsgi (pid=7748): SystemExit exception raised by WSGI script '/opt/python/current/app/application.py' ignored.
[Sat Aug 08 23:43:35.994449 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] Traceback (most recent call last):
[Sat Aug 08 23:43:35.994511 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] File "/opt/python/current/app/application.py", line 3, in <module>
[Sat Aug 08 23:43:35.994518 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] app.run(debug=True)
[Sat Aug 08 23:43:35.994553 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 772, in run
[Sat Aug 08 23:43:35.994560 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] run_simple(host, port, self, **options)
[Sat Aug 08 23:43:35.994590 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] File "/opt/python/run/venv/lib/python3.4/site-packages/werkzeug/serving.py", line 623, in run_simple
[Sat Aug 08 23:43:35.994596 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] reloader_type)
[Sat Aug 08 23:43:35.994624 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] File "/opt/python/run/venv/lib/python3.4/site-packages/werkzeug/_reloader.py", line 231, in run_with_reloader
[Sat Aug 08 23:43:35.994630 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] sys.exit(reloader.restart_with_reloader())
[Sat Aug 08 23:43:35.994652 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] SystemExit: 2
I'm using elasticbeanstalk command line interface to deploy the flask app.
You're using app.run in production. Don't use the dev server in production.
mod_wsgi, like any WSGI app server, expects to find an application instance when importing, but you're running the dev server instead.
Guard against running the dev server on import. Depending on your mod_wsgi settings, it may expect the name application instead of app as well.
application = app
if __name__ == '__main__':
app.run()

How to set environ variables in local development with virtualenv

I am currently trying to publish via ZIP my django app to an AWS elasticbeanstalk.
As I have a local and online development enviroment I would like to make use of the environ variables, that are used anyways by AWS.
For my development environments I am already using virtualenv. Apache runs with wsgi enabled and is supposed to use such environments. Unfortunately, it does not know the environ that I have set in the bin/activate.
Django throws a 500 error, since it cannot connect to the database as it does not have access to the environ vars:
1:53.862779 2015] [wsgi:error] [pid 20639] [remote 127.0.0.1:51896] KeyError: 'RDS_DB_NAME'
If I activate my env and look into the env vars:
(myenv)[bs#debian-gohan:]/var/www/vhosts/mysite $ env | grep RDS
RDS_HOSTNAME=localhost
... and I get the others as well...
My Apache Vhost is:
<VirtualHost *:80>
WSGIDaemonProcess mysite python-path=/home/bs/envs/myenv/bin/python2.7:/home/bs/envs/myenv/lib/python2.7/site-packages
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/vhosts/main-page/mysite/wsgi.py
Does anyone have an idea why the environ vars are not seen by the apache ?
EDIT 1:
I have tried to use SetEnv in the Apache config, like this:
SetEnv RDS_HOSTNAME "localhost"
Unfortunately, this did not work. I then removed the ProcessGroup and only used a simple WSGIPythonPath. That did not work either.
The error in the apache log remains the same:
[Thu Mar 26 11:30:34.046807 2015] [wsgi:info] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012, process='', application='mysite.dbz.dev|'): Loading WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py'.
[Thu Mar 26 11:30:34.178717 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012): Target WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py' cannot be loaded as Python module.
[Thu Mar 26 11:30:34.178812 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012): Exception occurred processing WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py'.
[Thu Mar 26 11:30:34.178924 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] Traceback (most recent call last):
[Thu Mar 26 11:30:34.178947 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/var/www/vhosts/main-page/mysite/wsgi.py", line 17, in <module>
[Thu Mar 26 11:30:34.179111 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] application = get_wsgi_application()
[Thu Mar 26 11:30:34.179157 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Thu Mar 26 11:30:34.179319 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] django.setup()
[Thu Mar 26 11:30:34.179363 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 20, in setup
[Thu Mar 26 11:30:34.179606 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Mar 26 11:30:34.179651 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 46, in __getattr__
[Thu Mar 26 11:30:34.179774 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] self._setup(name)
[Thu Mar 26 11:30:34.179789 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
[Thu Mar 26 11:30:34.179918 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] self._wrapped = Settings(settings_module)
[Thu Mar 26 11:30:34.179959 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 94, in __init__
[Thu Mar 26 11:30:34.180072 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Mar 26 11:30:34.180112 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu Mar 26 11:30:34.180220 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] __import__(name)
[Thu Mar 26 11:30:34.180246 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/var/www/vhosts/main-page/mysite/../mysite/settings.py", line 94, in <module>
[Thu Mar 26 11:30:34.180400 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] 'NAME': os.environ['RDS_DB_NAME'],
[Thu Mar 26 11:30:34.180443 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
[Thu Mar 26 11:30:34.180613 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] raise KeyError(key)
[Thu Mar 26 11:30:34.180665 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] KeyError: 'RDS_DB_NAME'
Set like this
<VirtualHost hostname:80>
...
SetEnv VARIABLE_NAME variable_value
...
</VirtualHost>
In wsgi script.
os.environ.setdefault("variable", "value")
To override variable,
os.environ['var']="val"

Categories