I have had django running with mod_python for awhile now but today I get the following error
MOD_PYTHON ERROR
ProcessId: 4551
Interpreter: 'thatch'
ServerName: 'thatch'
DocumentRoot: '/var/www/thatch'
URI: '/'
Location: '/'
Directory: None
Filename: '/var/www/thatch/'
PathInfo: ''
Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1202, in _process_target
module = import_module(module_name, path=path)
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 304, in import_module
return __import__(module_name, {}, {}, ['*'])
ImportError: No module named django.core.handlers.modpython
This is my virtual host configuration
<VirtualHost *:80>
ServerName thatch
DocumentRoot /var/www/thatch
<Location "/">
SetHandler python-program
PythonPath "['/var/www/thatch'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE thatch.settings
PythonOption django.root /var/www/thatch
PythonDebug On
</Location>
<Location "/media">
SetHandler None
</Location>
<LocationMatch "\.(jpg|gif|png|css|js)$">
SetHandler None
</LocationMatch>
</VirtualHost>
Any ideas why this is happening?
I can only guess what your problem might be, but here are two standard checks:
Import modpython in shell, from a couple different working directories
Change users (if you have any besides root set up) and repeat step 1
If #2 looks like more trouble than it's worth, then try very, very carefully examining permissions for each folder along the path to modpython to make sure that "other" has read access at every stage along the way. If you've moved django into your home directory (like I did once...not sure why, but got the same error) that'll be the problem. You either need to move it back into a directory where apache can read or you need to add read permission for other.
In my case pytonpath and access rights was ok.
This error disappeared after recompilation python.
Configuration:
Gentoo
Django 1.1
Apache:
www-servers/apache-2.2.15 USE="doc ssl suexec threads -debug -ldap (-selinux) -static" APACHE2_MODULES="alias auth_basic authn_alias authn_anon authn_default authn_file authz_default authz_host authz_owner autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias -actions -asis -auth_digest -authn_dbd -authn_dbm -authz_dbm -authz_groupfile -authz_user -cern_meta -charset_lite -dbd -dumpio -ident -imagemap -log_forensic -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -substitute -version" APACHE2_MPMS="worker -event -itk -peruser -prefork"
Python 2.6.4
Related
I'm trying to host my flask application on apache2 running on ubuntu 20.04. I have wsgi already enabled as well as the site. I believe the error might be because of wrong configuration but the error log suggests something about no python frame. Here's a copy of the error log from /var/log/apache2/error.log `
Current thread 0x00007f281d459c40 (most recent call first):
<no Python frame>
[Sat Jul 02 14:10:24.169227 2022] [wsgi:warn] [pid 23151:tid 139810266520640] mod_wsgi (pid=23151): Python home /home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9 is not a directory. Python interpreter may not be able to be initialized correctly. Verify the supplied path.
Python path configuration:
PYTHONHOME = '/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9'
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/usr/bin/python3'
sys.base_prefix = '/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9'
sys.base_exec_prefix = '/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9'
sys.executable = '/usr/bin/python3'
sys.prefix = '/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9'
sys.exec_prefix = '/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9'
sys.path = [
'/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9/lib/python38.zip',
'/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9/lib/python3.8',
'/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9/lib/python3.8/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
`
I have a package structure for my flask app allowing me to run it with python3 run.py but when importing flask_app I use from attend import app as application as shown in my wsgi file below.
import sys
import logging
logging.basicConfig(level=logging.DEBUG, filename='/var/www/html/SCHEYE/logs/SCHEYE.log', format='%(asctime)s %(message)s')
sys.path.insert(0, '/var/www/html/SCHEYE')
sys.path.insert(0, '/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9')
from attend import app as application
Here's a copy of my .conf file
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
ServerName 192.168.0.105
ServerAlias 192.168.0.105
DocumentRoot /var/www/html/SCHEYE
WSGIDaemonProcess SCHEYE threads=5 python-home=/home/dancungerald/.local/share/virtualenvs/SCHEYE-zGV6jY25/bin/python3.9
WSGIScriptAlias / /var/html/SCHEYE/SCHEYE.wsgi
WSGIApplicationGroup %{GLOBAL}
<Directory /var/www/html/SCHEYE>
WSGIProcessGroup SCHEYE
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
I have not yet registered a domain name for my site and I would like to ask if I can use my ip address as the ServerName and ServerAlias or could I simply enter an unregistered domain name? Sorry if the question is too obvious or redundant as I'm quite new to deployment this being my first. Thank you in advance.
Ok, after 5-6 hours of trying, I give up. I have searched the web, tried all solutions suggested, but nothing is solving my problem.
Goal: Set up Django on my Ubuntu 12.04 VPS.
Problem: Exception occurred processing WSGI script [...] ImportError: No module named django.core.handlers.wsgi in /etc/log/apache2/error.log.
Solutions tried: 1) Appending the site-packages directory to the sys path in Djangos' wsgi.py file, 2) re-installing mod_wsgi, 3) making sure mod_wsgi is compiled for the same Python version as Django is installed with, 4) chmod 777 for the site-packages directory.
Environment: Ubuntu 12.04 VPS, Django installation in virtualenv, Python version 2.7.3, Django version 1.6.1, mod_wsgi built from mod_wsgi-3.4.tar.gz.
Full error message:
mod_wsgi (pid=23691): Exception occurred processing WSGI script '/var/www/mySite/djangoSite/djangoSite/wsgi.py'.
Traceback (most recent call last):
File "/var/www/mySite/djangoSite/djangoSite/wsgi.py", line 7, in <module>
import django.core.handlers.wsgi
ImportError: No module named django.core.handlers.wsgi
mod_wsgi (pid=23691): Target WSGI script '/var/www/mySite/djangoSite/djangoSite/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=23691): Exception occurred processing WSGI script '/var/www/mySite/djangoSite/djangoSite/wsgi.py'.
Traceback (most recent call last):
File "/var/www/mySite/djangoSite/djangoSite/wsgi.py", line 7, in <module>
import django.core.handlers.wsgi
ImportError: No module named django.core.handlers.wsgi
Conf file from sites-available:
<VirtualHost *:80>
ServerAdmin admin#mysite.com
ServerName mysite.com
DocumentRoot /var/www/mysite.com/djangoSite
WSGIDaemonProcess djangoSite python-path=/var/www/mysite.com/djangoSite:~/Envs/myEnv/lib/python2.7/site-packages
WSGIProcessGroup djangoSite
WSGIScriptAlias / /var/www/mysite.com/djangoSite/djangoSite/wsgi.py
Alias /static/ /var/www/mysite.com/djangoSite/static/
<Directory /var/www/mysite.com/djangoSite/static>
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/mysite.com/djangoSite/djangoSite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
wsgi.py:
import os
import sys
sys.path.append('/var/www/mysite.com/djangoSite/')
sys.path.append('/var/www/mysite.com/djangoSite/djangoSite/')
activate_this = '/root/Envs/myenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoSite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Site structure
/var/www/
-- mysite.com
-- djangoSite
-- manage.py
-- djangoSite
-- settings.py, wsgi.py etc.
In your wsgi.py, try adding this to activate virtual env:
import os
import sys
sys.path.append('/Path_To/Virtual_Env/Project_Dir/')
#This is important if multiple apps are running (instead of setdefault)
os.environ["DJANGO_SETTINGS_MODULE"] = "app_name.settings"
activate_this = '/Path_To/Virtual_Env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
In you apache config, you mainly need only(No Deamon Process required):
WSGIScriptAlias / /var/www/mysite.com/djangoSite/djangoSite/wsgi.py
Alias /static/ /var/www/mysite.com/djangoSite/static/
See from the Create Virtual Host section of this link
Make sure you are using absolute paths in your Apache2 config file. I assume you have been able to run python manage.py shell to get a working Django shell? I would tackle the Apache2 config file; I'm sure your issue is there.
~/Envs/myEnv/lib/python2.7/site-packages
I think that's your problem right there: the ~ is, if it is expanded at all, expanded to the home of the www-data user. You can validate that by doing something like this:
import sys
print >> sys.stderr, sys.path
in your wsgi file; then check your error log. If it doesn't end up in the main error log, add an ErrorLog to your vhost to get per-vhost error logging.
Also, /root/ is not readable for the www-data user, you need to move your virtual env somewhere accessible.
Originally when I installed Django 1.3 with wsgi on my ubuntu server I used the included setup.py file and so when I wanted to update followed the Remove any old versions of Django section of the install guide by renaming the "django" folder in my site-packages "django.old" and then installing the new version by using the the setup.py file for Django 1.4
After restarting my apache server I got a standard 500 Internal error. I checked the apache error log and discovered that ADMIN_MEDIA_PREFIX has been deprecated so following the Django 1.4 release notes I removed ADMIN_MEDIA_PREFIX from the settings file and moved the admin files into the static directory under a folder called "admin" as indicated.
I restarted my apache server again and received the same standard 500 error but this time when I tried running a tail on the apache error log no new errors registered.
Without any further error messages I am really stuck so any help will be appreciated.
Below is the content of my apache site config file and the wsgi file
site config:
<VirtualHost *:80>
ServerAdmin me#mysite.com
ServerName www.mysite.com
ServerAlias mysite.com
# Indexes + Directory Root.
# DirectoryIndex index.html index.htm index.php
DocumentRoot /home/www/www.mysite.com/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /home/www/www.mysite.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /home/www/www.mysite.com/logs/error.log
CustomLog /home/www/www.mysite.com/logs/access.log combined
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/www/www.mysite.com/htdocs/>
Options FollowSymLinks MultiViews
AllowOverride All
allow from all
</Directory>
### Connect Django to the URL using WSGI (the django recommended method)
WSGIScriptAlias /myproject /django/myproject/django.wsgi
### Alias to the location of the static dir (images, css, js etc.)
Alias /myproject/static /django/myproject/static
<Directory /django/myproject/static>
Order deny,allow
allow from all
</Directory>
</VirtualHost>
django.wsgi:
import sys
import os
import django.core.handlers.wsgi
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
application = django.core.handlers.wsgi.WSGIHandler()
sys.path.insert(0, '/django/myproject/')
sys.path.insert(0, '/django/myproject/')
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
Please note I have tried to remove or rename any identifying information from these files for security reasons, so if there is an obvious syntax error etc. it is probably due to this editing. The original versions of these files are the same accept for the name changes and worked well under Django 1.3
django 1.4 have a wsgi.py file configuratiom included:
See the documentation:
https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/#the-application-object
I found a similar question here, but didn't help me.
I basically have apache setup on my OS X. I also have Django installed.
However, when i try to load the page through the browser locally, i get:
Forbidden
You don't have permission to access / on this server.
I have an original httpd.conf with the only modification of enabling vhosts in which I have:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/Dropbox/project/www/"
ServerName touch.loc
# ServerAlias www.dummy-host.example.com
ErrorLog "/Dropbox/project/www/log/error.log"
CustomLog "/Dropbox/project/www/log/access.log" common
</VirtualHost>
And the error.log file gives:
[Tue May 03 20:22:56 2011] [error] [client 127.0.0.1] Directory index forbidden by Options directive: /Dropbox/project/www/
I read around and it looks like i have to add the following to the httpd.conf:
<Directory /Dropbox/project/www >
Order deny,allow
Allow from all
</Directory>
In which case i get:
[Tue May 03 20:27:55 2011] [error] [client 127.0.0.1] client denied by server configuration: /Dropbox/project/www/
Can someone help me fix this annoyance? How can I further Investigate it?
Does it have to do with users/groups?
UPDATE:
I then added the Options +Indexes and the permissions opened. However when i try to load the page, file structure appears instead of the wsgi file to pickup and load the website. What would be the reason for that?
here is my .wsgi file:
import os
import sys
sys.stdout = sys.stderr
# Add the virtual Python environment site-packages directory to the path
import site
site.addsitedir('/usr/lib/python2.6/dist-packages')
#If your project is not on your PYTHONPATH by default you can add the following
sys.path.append('/Dropbox/project/www/')
sys.path.append('/Dropbox/project/www/project')
# Avoid ``[Errno 13] Permission denied: '/var/www/.python-eggs'`` messages
os.environ['PYTHON_EGG_CACHE'] = '/Dropbox/project/www/mod_wsgi/egg-cache'
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
You seem to be missing anything in your Apache configuration that actually serves the Django application. You need to read the Django mod_wsgi documentation - the first line of code there is what you're missing.
Note that your code should not live under the DocumentRoot.
The problem I see is in Dropbox folder
I have made so:
chmod o+x /home/your_name/Dropbox
That resolves permissions
I'm trying to deploy a django project via mod_python and I keep getting an error saying a handler module is missing.
My apache config:
<Location />
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE bookmarklet_server.settings
PythonOption django.root /
PythonDebug On
#PythonPath "['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/pymodules/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages']"
</Location>
The other path is from my attempt to just copy over the default pythonpath, but it didn't help.
A quick test in the python console shows the module should be accesible:
Python 2.6.4 (r264:75706, Nov 2 2009, 14:44:17)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django.core.handlers.modpython
no errors
However loading the site, this error is inadvertendly returned:
MOD_PYTHON ERROR
ProcessId: 8926
Interpreter: '<ip>'
ServerName: '<ip>'
DocumentRoot: '/htdocs'
URI: '/'
Location: '/'
Directory: None
Filename: '/htdocs'
PathInfo: '/'
Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1202, in _process_target
module = import_module(module_name, path=path)
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 304, in import_module
return __import__(module_name, {}, {}, ['*'])
ImportError: No module named django.core.handlers.modpython
Perhaps django isn't in your Pythonpath?
Ok, managed to fix the problem.
This particular import issue was fixed by installing django rather than just having the svn trunk linked into dist-packages. Why this doesn't work for server processes I don't know.
But anyway, there were further issues which were solved by doing a CGI deployment via nginx and eventually the last problem (which also failed my wsgi deployment attempt) was that my /home dir, which is where the files were, was accessible only by myself.
I learned a lot today :)