Deploying django3 project with mod_wsgi - python

I'm experimenting to publish my django project with Apache mod_wsgi. I created a simple django3 project named sampleapp in virtualenv. Then, I configured my /etc/apache2/sites-enabled/000-default.conf file as follows
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIDaemonProcess sampleapp python-home=/var/www/html/sampleapp/env python-path=/var/www/html/sampleapp:/var/www/html/sampleapp/env/lib/python3.7/site-packages
WSGIProcessGroup sampleapp
WSGIScriptAlias /sampleapp /var/www/html/sampleapp/sampleapp/wsgi.py process-group=sampleapp
</VirtualHost>
Although my virtualenv's python version is 3.7, mod_wsgi is used system's python version(3.5), so it doesn't see my virtualenv and doesn't use its python version. My apache error log as follows:
[Sat Feb 20 15:36:02.390188 2021] [mpm_prefork:notice] [pid 20090] AH00169: caught SIGTERM, shutting down
[Sat Feb 20 15:36:03.226065 2021] [mpm_prefork:notice] [pid 20204] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Sat Feb 20 15:36:03.226278 2021] [core:notice] [pid 20204] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 20 15:36:03.294321 2021] [wsgi:error] [pid 20207] mod_wsgi (pid=20207): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Sat Feb 20 15:36:03.295568 2021] [wsgi:error] [pid 20207] mod_wsgi (pid=20207): Call to 'site.addsitedir()' failed for '/var/www/html/sampleapp/env/lib/python3.7/site-packages'.
[Sat Feb 20 15:36:07.084368 2021] [wsgi:error] [pid 20207] mod_wsgi (pid=20207): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Sat Feb 20 15:36:07.084455 2021] [wsgi:error] [pid 20207] mod_wsgi (pid=20207): Call to 'site.addsitedir()' failed for '/var/www/html/sampleapp/env/lib/python3.7/site-packages'.
[Sat Feb 20 15:36:07.085660 2021] [wsgi:error] [pid 20207] [remote 127.0.0.1:47028] mod_wsgi (pid=20207): Target WSGI script '/var/www/html/sampleapp/sampleapp/wsgi.py' cannot be loaded as Python module.
[Sat Feb 20 15:36:07.085769 2021] [wsgi:error] [pid 20207] [remote 127.0.0.1:47028] mod_wsgi (pid=20207): Exception occurred processing WSGI script '/var/www/html/sampleapp/sampleapp/wsgi.py'.
[Sat Feb 20 15:36:07.086188 2021] [wsgi:error] [pid 20207] [remote 127.0.0.1:47028] Traceback (most recent call last):
[Sat Feb 20 15:36:07.086266 2021] [wsgi:error] [pid 20207] [remote 127.0.0.1:47028] File "/var/www/html/sampleapp/sampleapp/wsgi.py", line 12, in <module>
[Sat Feb 20 15:36:07.086280 2021] [wsgi:error] [pid 20207] [remote 127.0.0.1:47028] from django.core.wsgi import get_wsgi_application
[Sat Feb 20 15:36:07.086321 2021] [wsgi:error] [pid 20207] [remote 127.0.0.1:47028] ImportError: No module named 'django'
How do I configure mod_wsgi to use the python version of my venv? Or where is my fault? Thanks for the answers.

So the mod_wsgi is compiled to a specific version of Python for Apache. You cannot make it run a different version of python. You can either rebuild that mod_wsgi to the correct version, or change the virtual environment. This deletes virtualenv wrapper but keeps project files.
I think that "changing the virtualenv" would be easier.
rmvirtualenv env-name
mkvirtualenv -p python3.5 env-name
setvirtualenvproject env-name
When you use 'mkvirtualenv' use the -r tag for a requirements.txt
Or rebuild the mod_wsgi:
Documentation

Related

ImportError: No module named cx_Oracle in apache

I deploy flask with apache on CentOS7
And I want Oracle database to insert or select when user access.
So I install cx_Oracle
pip install cx_Oracle
And run flask on virtual env.
flask run
It work with no error.
But I access to localhost:80 using apache, It occur Internal Server Error 500.
In error_log
[Fri Oct 23 09:12:34.623473 2020] [mpm_prefork:notice] [pid 475] AH00170: caught SIGWINCH, shutting down gracefully
[Fri Oct 23 09:12:35.678302 2020] [lbmethod_heartbeat:notice] [pid 510] AH02282: No slotmem from mod_heartmonitor
[Fri Oct 23 09:12:35.681622 2020] [mpm_prefork:notice] [pid 510] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Fri Oct 23 09:12:35.681665 2020] [core:notice] [pid 510] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Fri Oct 23 09:12:38.074902 2020] [:error] [pid 513] [client 172.17.0.1:33640] mod_wsgi (pid=513): Target WSGI script '/var/www/hitme/wsgi.py' cannot be loaded as Python module.
[Fri Oct 23 09:12:38.074946 2020] [:error] [pid 513] [client 172.17.0.1:33640] mod_wsgi (pid=513): Exception occurred processing WSGI script '/var/www/hitme/wsgi.py'.
[Fri Oct 23 09:12:38.074973 2020] [:error] [pid 513] [client 172.17.0.1:33640] Traceback (most recent call last):
[Fri Oct 23 09:12:38.074994 2020] [:error] [pid 513] [client 172.17.0.1:33640] File "/var/www/hitme/wsgi.py", line 10, in <module>
[Fri Oct 23 09:12:38.075058 2020] [:error] [pid 513] [client 172.17.0.1:33640] from app import app as application
[Fri Oct 23 09:12:38.075070 2020] [:error] [pid 513] [client 172.17.0.1:33640] File "/var/www/hitme/app/__init__.py", line 4, in <module>
[Fri Oct 23 09:12:38.075138 2020] [:error] [pid 513] [client 172.17.0.1:33640] import cx_Oracle
[Fri Oct 23 09:12:38.075162 2020] [:error] [pid 513] [client 172.17.0.1:33640] ImportError: No module named cx_Oracle
I followed this article for deploy flask with apache.
https://dev.to/sm0ke/flask-deploy-with-apache-on-centos-minimal-setup-2kb7
and install cx_Oracle and I copied it where I thought I needed it.
Here my tree
/etc/httpd/modules/
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
/var/www/hitme/lib/python3.6/site-packages
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
/usr/local/lib/python3.6/site-packages
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
But it still gives the error.
Is there any other way?
Ensure that the required Oracle Instant Client is installed to the Apache user by downloading
https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-basic-linux.x64-19.9.0.0.0dbru.zip
and unzip ut to a folder Apache user owns or is accessible for read and execute - lets say
/apache/oracle
After that, ensure PATH, ORACLE_HOME and LD_LIBRARY_PATH ist set properly as Apache User - i.e.
export ORACLE_HOME=/apache/oracle
export PATH=$PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
If you start Apache as service then you may need to set the variables to root or user who starts apache.

Target WSGI script myapp.wsgi' cannot be loaded as Python module, ModuleNotFoundError: No module named 'flask'

I a trying to run a "hello world" python application from the server using Apache web server port 80. Here, I have setup python virtual environment compacting with python version 3.8. created virtual host, wsgi file and now trying to call the URL on browser, I am getting 500 internal server error. Apache error log file details provided here.
1. Ubuntu 18.04,
2. Python 3.8,
3. Apache 2.4
Virtual host configuration
#WSGIDaemonProcess MyApp python-home=/usr/local/env/myApp/venv threads=5i
WSGIDaemonProcess Myapp user=www-data group=www-data python-home=/usr/local/env/myApp/venv python-path=/usr/local/env/myApp threads=5
WSGIScriptAlias /project_wsgi /usr/local/env/myApp/myapp.wsgi
#WSGIProcessGroup myApp
WSGIApplicationGroup Myapp
#WSGIImportScript %{GLOBAL}
#WSGIPythonHome /usr/local/env/myApp/venv
<VirtualHost *:80>
<Directory /usr/local/env/myApp>
Require all granted
Order allow,deny
Allow from all
LogLevel info
</Directory>
</VirtualHost>
WSGI file
import os
import sys
sys.path.insert(0, '/usr/local/env/myApp/')
python_home = '/usr/local/env/myApp/venv'
#activate_this = '/usr/local/env/myApp/venv/bin/activate_this.py'
#with open(activate_this) as file_:
# exec(file_.read(), dict(__file__=activate_this))
from app.myApp import app as application
apache error logs
[Fri Jan 31 16:00:28.990978 2020] [wsgi:info] [pid 58589:tid 140712013437888] mod_wsgi (pid=58589): Starting process 'Myapp' with uid=33, gid=33 and threads=5.
[Fri Jan 31 16:00:28.991819 2020] [wsgi:info] [pid 58589:tid 140712013437888] mod_wsgi (pid=58589): Python home /usr/local/env/myApp/venv.
[Fri Jan 31 16:00:28.991863 2020] [wsgi:info] [pid 58589:tid 140712013437888] mod_wsgi (pid=58589): Initializing Python.
[Fri Jan 31 16:00:28.991926 2020] [mpm_event:notice] [pid 102854:tid 140712013437888] AH00489: Apache/2.4.29 (Ubuntu) mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Fri Jan 31 16:00:28.991937 2020] [mpm_event:info] [pid 102854:tid 140712013437888] AH00490: Server built: 2019-09-16T12:58:48
[Fri Jan 31 16:00:28.991952 2020] [core:notice] [pid 102854:tid 140712013437888] AH00094: Command line: '/usr/sbin/apache2'
[Fri Jan 31 16:00:28.993170 2020] [wsgi:info] [pid 58591:tid 140712013437888] mod_wsgi (pid=58591): Initializing Python.
[Fri Jan 31 16:00:28.993874 2020] [wsgi:info] [pid 58590:tid 140712013437888] mod_wsgi (pid=58590): Initializing Python.
[Fri Jan 31 16:00:29.061111 2020] [wsgi:info] [pid 58589:tid 140712013437888] mod_wsgi (pid=58589): Attach interpreter ''.
[Fri Jan 31 16:00:29.088271 2020] [wsgi:info] [pid 58589:tid 140712013437888] mod_wsgi (pid=58589): Adding '/usr/local/env/myApp' to path.
[Fri Jan 31 16:00:29.089075 2020] [wsgi:info] [pid 58591:tid 140712013437888] mod_wsgi (pid=58591): Attach interpreter ''.
[Fri Jan 31 16:00:29.089966 2020] [wsgi:info] [pid 58590:tid 140712013437888] mod_wsgi (pid=58590): Attach interpreter ''.
[Fri Jan 31 16:02:22.375687 2020] [wsgi:info] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] mod_wsgi (pid=58591, process='', application='Myapp'): Loading WSGI script '/usr/local/env/myApp/myapp.wsgi'.
[Fri Jan 31 16:02:22.381101 2020] [wsgi:error] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] mod_wsgi (pid=58591): Target WSGI script '/usr/local/env/myApp/myapp.wsgi' cannot be loaded as Python module.
[Fri Jan 31 16:02:22.381132 2020] [wsgi:error] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] mod_wsgi (pid=58591): Exception occurred processing WSGI script '/usr/local/env/myApp/myapp.wsgi'.
[Fri Jan 31 16:02:22.381374 2020] [wsgi:error] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] Traceback (most recent call last):
[Fri Jan 31 16:02:22.381400 2020] [wsgi:error] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] File "/usr/local/env/myApp/myapp.wsgi", line 10, in <module>
[Fri Jan 31 16:02:22.381405 2020] [wsgi:error] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] from app.myApp import app as application
[Fri Jan 31 16:02:22.381411 2020] [wsgi:error] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] File "/usr/local/env/myApp/app/myApp.py", line 1, in <module>
[Fri Jan 31 16:02:22.381414 2020] [wsgi:error] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] from flask import Flask
[Fri Jan 31 16:02:22.381436 2020] [wsgi:error] [pid 58591:tid 140711785658112] [client 146.176.178.57:50395] ModuleNotFoundError: No module named 'flask'
I have installed flask on the virtual environment and trying to activate from the WSGI file execution. However, this is not working for me.
FYI : The commented lines on virtual host is already I have tried.

pgAdmin4 install - Target WSGI script cannot be loaded as Python module

This question has been asked before here but the solution does not work for me. My python venv configuration is not playing well with the apache2 mod_wsgi and I cannot root-cause the issue. At present, I cannot comment on this question so I'm posting another one
Here are the apache2 error logs when trying to log into the site.
[Fri Dec 07 20:32:25.476491 2018] [wsgi:warn] [pid 25982:tid 140573456193408] mod_wsgi: Compiled for Python/3.5.1+.
[Fri Dec 07 20:32:25.476529 2018] [wsgi:warn] [pid 25982:tid 140573456193408] mod_wsgi: Runtime using Python/3.5.2.
[Fri Dec 07 20:32:25.477326 2018] [mpm_event:notice] [pid 25982:tid 140573456193408] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Fri Dec 07 20:32:25.477362 2018] [core:notice] [pid 25982:tid 140573456193408] AH00094: Command line: '/usr/sbin/apache2'
[Fri Dec 07 20:34:24.401510 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] mod_wsgi (pid=25983): Target WSGI script '/home/awashburn/anaconda3/envs/pgadmin4/lib/python3.7/site-packages/pgadmin4/pgAdmin4.wsgi' cannot be loaded as Python module.
[Fri Dec 07 20:34:24.401642 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] mod_wsgi (pid=25983): Exception occurred processing WSGI script '/home/awashburn/anaconda3/envs/pgadmin4/lib/python3.7/site-packages/pgadmin4/pgAdmin4.wsgi'.
[Fri Dec 07 20:34:24.402195 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] Traceback (most recent call last):
[Fri Dec 07 20:34:24.402229 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] File "/home/awashburn/anaconda3/envs/pgadmin4/lib/python3.7/site-packages/pgadmin4/pgAdmin4.wsgi", line 25, in <module>
[Fri Dec 07 20:34:24.402236 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] import config
[Fri Dec 07 20:34:24.402244 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] File "/home/awashburn/anaconda3/envs/pgadmin4/lib/python3.7/site-packages/pgadmin4/config.py", line 29, in <module>
[Fri Dec 07 20:34:24.402248 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] from pgadmin.utils import env, IS_PY2, IS_WIN, fs_short_path
[Fri Dec 07 20:34:24.402256 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] File "/home/awashburn/anaconda3/envs/pgadmin4/lib/python3.7/site-packages/pgadmin4/pgadmin/__init__.py", line 18, in <module>
[Fri Dec 07 20:34:24.402260 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] from flask import Flask, abort, request, current_app, session, url_for
[Fri Dec 07 20:34:24.402280 2018] [wsgi:error] [pid 25983:tid 140573343934208] [remote 10.2.5.243:15047] ImportError: No module named 'flask'
Here is the Vhost configuration:
<VirtualHost *>
ServerName shinyapp01t
WSGIDaemonProcess pgadmin processes=1 threads=25 python-home=/home/awashburn/anaconda3/envs/pgadmin4 display-name=pgadmin4
WSGIScriptAlias /pgadmin /home/awashburn/anaconda3/envs/pgadmin4/lib/python3.7/site-packages/pgadmin4/pgAdmin4.wsgi
<Directory "/home/awashburn/anaconda3/envs/pgadmin4/lib/python3.7/site-packages/pgadmin4/">
WSGIProcessGroup pgadmin
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>
I referenced these instructions from DigitalOcean trying to install pgAdmin4 on Ubuntu 16.04.
Edit: I used a python3 venv instead of anaconda virtual env and everything worked fine. So the root cause is the anaconda system. There's a discussion on the mod_wsgi mailing list about this

mod-wsgi error Target WSGI script cannot be loaded as Python module

Apache 2.4.10 and mod-wsgi 4.4 environments.
Below is apache error log file :
[Wed Nov 02 11:15:21.360055 2016] [wsgi:error] [pid 3729:tid 140033629607680] [remote 10.10.200.99:7425] mod_wsgi (pid=3729): Target WSGI script '/home/service/was/test/test_app.wsgi' cannot be loaded as Python module.
[Wed Nov 02 11:15:21.360060 2016] [wsgi:error] [pid 3729:tid 140033629607680] [remote 10.10.200.99:7425] mod_wsgi (pid=3729): Exception occurred processing WSGI script '/home/service/was/test/test_app.wsgi'.
[Wed Nov 02 11:15:21.360067 2016] [wsgi:error] [pid 3729:tid 140033629607680] [remote 10.10.200.99:7425] Traceback (most recent call last):
[Wed Nov 02 11:15:21.360075 2016] [wsgi:error] [pid 3729:tid 140033629607680] [remote 10.10.200.99:7425] File "/home/service/was/test/test_app.wsgi", line 6, in <module>
[Wed Nov 02 11:15:21.360119 2016] [wsgi:error] [pid 3729:tid 140033629607680] [remote 10.10.200.99:7425] from test_app import app as application
[Wed Nov 02 11:15:21.360125 2016] [wsgi:error] [pid 3729:tid 140033629607680] [remote 10.10.200.99:7425] File "/home/service/was/test/test_app.py", line 3, in <module>
[Wed Nov 02 11:15:21.360141 2016] [wsgi:error] [pid 3729:tid 140033629607680] [remote 10.10.200.99:7425] from flask import Flask
[Wed Nov 02 11:15:21.360158 2016] [wsgi:error] [pid 3729:tid 140033629607680] [remote 10.10.200.99:7425] ImportError: No module named flask
And I set httpd-virtualhost.conf:
Listen 10003
<VirtualHost *:10003>
# mod_wsgi global settings
WSGIApplicationGroup %{RESOURCE}
ErrorLog "|/usr/local/server/apache/bin/rotatelogs /home/log/apache/error-%Y-%m-%d.log 86400 +540"
TransferLog "|/usr/local/server/apache/bin/rotatelogs /home/log/apache/checkout/access-%Y-%m-%d.log 86400 +540"
#mod-wsgi : test
WSGIScriptAlias /test /home/service/was/test/test_app.wsgi
WSGIDaemonProcess test_app processes=4 threads=4 display-name=%{GROUP}
<Directory /home/service/was/test/ >
WSGIProcessGroup test_app
Require all granted
</Directory>
</VirtualHost>
And my wsgi script, test_App.wsgi and test_app.py:
#test_app.wsgi
import os, sys
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
sys.path.insert(0, '/home/service/was/test/')
print os
print sys
from test_app import app as application
In this setting, I run test_app.py in my dev-server.
Why generate 'Target WSGI script '/home/service/was/test/test_app.wsgi' cannot be loaded as Python module.' message?
Why do not import python module installed by pip?

Internal Server Error: Target WSGI script cannot be loaded as Python module AND IOError: [Errno 2] No such file or directory: 'client_secrets.json'

I am trying to run a Linux server configuration for a catalog project. I am using: Apache2, Flask, and SQLAlchemy and I had to install and configure PostgreSQL. The site I am trying to run is the Public IP Address: http://52.27.140.219/. I am happy to provide greater detail. I am new with Linux and many things discussed here, but I believe my work is strong, except for the end problem below.
Important steps in Terminal:
From:
(venv)grader#ip-10-20-8-44:/var/www/catalog/catalog$ sudo service apache2 restart
[sudo] password for grader:
* Restarting web server apache2 [ OK ]
Error Logs
(venv)grader#ip-10-20-8-44:/var/www/catalog/catalog$ sudo tail -20 /var/log/apache2/error.log
[Wed Jul 01 16:51:36.873041 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704] Traceback (most recent call last):
[Wed Jul 01 16:51:36.873059 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704] File "/var/www/catalog/catalog.wsgi", line 7, in <module>
[Wed Jul 01 16:51:36.873105 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704] from catalog import app as application
[Wed Jul 01 16:51:36.873117 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704] File "/var/www/catalog/catalog/__init__.py", line 35, in <module>
[Wed Jul 01 16:51:36.873257 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704] open('client_secrets.json', 'r').read())['web']['client_id']
[Wed Jul 01 16:51:36.873279 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704] IOError: [Errno 2] No such file or directory: 'client_secrets.json'
[Wed Jul 01 16:53:36.405496 2015] [mpm_event:notice] [pid 14596:tid 140294245513088] AH00491: caught SIGTERM, shutting down
[Wed Jul 01 16:53:37.387879 2015] [mpm_event:notice] [pid 14715:tid 140705447798656] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Wed Jul 01 16:53:37.387939 2015] [core:notice] [pid 14715:tid 140705447798656] AH00094: Command line: '/usr/sbin/apache2'
[Wed Jul 01 17:35:23.312436 2015] [mpm_event:notice] [pid 14715:tid 140705447798656] AH00491: caught SIGTERM, shutting down
[Wed Jul 01 17:35:24.360945 2015] [mpm_event:notice] [pid 15120:tid 140719357745024] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Wed Jul 01 17:35:24.361007 2015] [core:notice] [pid 15120:tid 140719357745024] AH00094: Command line: '/usr/sbin/apache2'
[Wed Jul 01 17:35:35.741239 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] mod_wsgi (pid=15123): Target WSGI script '/var/www/catalog/catalog.wsgi' cannot be loaded as Python module.
[Wed Jul 01 17:35:35.741269 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] mod_wsgi (pid=15123): Exception occurred processing WSGI script '/var/www/catalog/catalog.wsgi'.
[Wed Jul 01 17:35:35.741302 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] Traceback (most recent call last):
[Wed Jul 01 17:35:35.741317 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] File "/var/www/catalog/catalog.wsgi", line 7, in <module>
[Wed Jul 01 17:35:35.741359 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] from catalog import app as application
[Wed Jul 01 17:35:35.741369 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] File "/var/www/catalog/catalog/__init__.py", line 35, in <module>
[Wed Jul 01 17:35:35.741483 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] open('client_secrets.json', 'r').read())['web']['client_id']
[Wed Jul 01 17:35:35.741501 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] IOError: [Errno 2] No such file or directory: 'client_secrets.json'
When I sudo nano /etc/apache2/sites-available/catalog.conf, I have:
WSGIPythonPath /var/www/catalog/catalog/venv/:/var/www/catalog/catalog/v$
<VirtualHost *:80>
ServerName 52.27.140.219
ServerAdmin admin#52.27.140.219
ServerAlias c-73-221-39-5.hsd1.wa.comcast.net
WSGIScriptAlias / /var/www/catalog/catalog.wsgi
<Directory /var/www/catalog/catalog/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/catalog/catalog/static
<Directory /var/www/catalog/catalog/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Don't use a relative path name to the file. Instead construct an absolute path name. This is needed because the current working directory of the process will not be where your code is located. Read:
https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Working_Directory
So as Graham said, eventually, you end up with something like:
APP_PATH = '/var/www/catalog/
CLIENT_ID = json.loads(open(APP_PATH + 'client_secrets.json', 'r').read())['web']['client_id']

Categories