Quijost
Servicios => English support (For non-Spaniard users) => Mensaje iniciado por: Lwoo en Marzo 08, 2012, 23:17:09 pm
-
Hi,
I've been trying to deploy my django project at monfloo.com, but got error 500. Actually I'm not sure what to do about that. :/
Also, I use PostgreSQL as my database. Trying to syncdb, I get "Error loading psycopg module: No module named psycopg". Not sure if I'm able to install the module myself (can't see virtualenv/virtualenvwrapper installed on the server, and easy_install needs root privileges) or just I have something configured improperly?
In general, the project is set up according to the guidelines from http://quijost.com/foro/desarrollo-web/ejemplo-de-prueba-index-py-para-django-y-mysql-con-mod_wgsi/ and https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/ (without the http.conf part of course ;)). However, I've run out of ideas what might be missing or done wrong. :/
-
Hi and welcome Lwoo,
We just installed psycopg2 v2.4.4 on server1 for give support to you. If you need some other module, just let me know.
When you write "import psycopg2" you need set previously the enviroment variable PYTHON_EGG_CACHE, for example:
import os
os.environ['PYTHON_EGG_CACHE'] = '/home/youruser/tmp/trac-eggs'
import psycopg2
It is important that you must set PYTHON_EGG_CACHE under you username folder. The folder /tmp is not writeable for some reason to python when it loads internal imports and you could get a error similar to (or error 500):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/psycopg2-2.4.4-py2.7-linux-x86_64.egg/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: /usr/local/lib/python2.7/site-packages/psycopg2-2.4.4-py2.7-linux-x86_64.egg/psycopg2/_psycopg.so: undefined symbol: lo_truncate
Regarding to error 500, the error_log by apache for cPanel is general, so the only way that I know to catch 500 errors is wrapper the code with a try/catch exception like:
filename = 'error_log.txt'
f = open(filename, 'w')
try:
# Do something with your code here
f.write('Ok')
except:
traceback.print_exc(file=f)
f.close()
Also searching on the general error_log I see this error for your site:
[Thu Mar 08 23:36:18 2012] [alert] [client XXX.XXX.XXX.XXX] /home/monfloo/public_html/monfloo-landing/.htaccess: Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration
[Thu Mar 08 23:36:18 2012] [alert] [client XXX.XXX.XXX.XXX] /home/monfloo/public_html/monfloo-landing/.htaccess: Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration
[Thu Mar 08 23:36:18 2012] [error] Optional hook test said: GET / HTTP/1.0
[Thu Mar 08 23:36:18 2012] [error] Optional function test said: GET / HTTP/1.0
[Thu Mar 08 19:36:19 2012] [alert] [client XXX.XXX.XXX.XXX] /home/monfloo/public_html/monfloo-landing/.htaccess: Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration
[Thu Mar 08 19:36:19 2012] [alert] [client XXX.XXX.XXX.XXX] /home/monfloo/public_html/monfloo-landing/.htaccess: Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration
Note that PythonHandler directive is only for mod_python and we are using mod_wsgi for python scripts that works with "SetHandler wsgi-script"
Please fix that and back to me again if you need more assistance.
-
Modified my settings.py to use psycopg2 and now got the following error message:
monfloo@monfloo.quijost.com [~/monfloo-lp/monfloo_lp]# python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/cor
e/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/cor
e/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/cor
e/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/cor
e/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/uti
ls/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/cor
e/management/commands/syncdb.py", line 7, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_
signal
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/cor
e/management/sql.py", line 6, in <module>
from django.db import models
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/
__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/
utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/
utils.py", line 33, in load_backend
return import_module('.base', backend_name)
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/uti
ls/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/
backends/postgresql_psycopg2/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: /usr
/local/lib/python2.7/site-packages/psycopg2-2.4.4-py2.7-linux-x86_64.egg/psycopg
2/_psycopg.so: undefined symbol: lo_truncate
monfloo@monfloo.quijost.com [~/monfloo-lp/monfloo_lp]#
-
I test on our sandbox example too http://quijost.com/sandbox/index.py
And I am getting a error like:
/usr/local/lib/python2.7/site-packages/psycopg2-2.4.4-py2.7-linux-x86_64.egg/psycopg2/_psycopg.so: undefined symbol: lo_truncate
On google a lot people complains about the error, but without a workaround. The most precise info that I could get was:
http://archives.postgresql.org/psycopg/2011-10/msg00020.php
lo_truncate is available after postgres 8.3. Psycopg is being compiled
again libpq 8.4, so the function is included. Looks like at runtime it
tries to dynamically link with an older libpq: you can check with ldd
which one.
So I gonna try debug and search on source code for make some changes on psycopg2 ang get it make available on postgres 9.1. But I cannot guarantee that I can make it work, seems a bug related with psycopg2.
While I try to fix, you could use MySqldb as a fallback alternative.
-
OK, I sticked to MySQL for the time being and managed to initiate syncdb, but another error appeared: https://gist.github.com/9d1de002073de9b974ae
-
I finally solve the problem, it seems a bug on psycopg 2.4.4 on the file psycopg/lobject_int.c:
.psycopg/lobject_int.c:478: retvalue = lo_truncate(self->conn->pgconn, self->fd, len);
http://www.postgresql.org/docs/9.0/static/lo-interfaces.html#LO-TRUNCATE
I install the development version that fix the bug, so now it is working:
# python -c "import psycopg2; print psycopg2.__version__"
2.4.5.dev0 (dt dec pq3 ext)
Try now with psycopg2 and manage.py if solves your problem and post here again your result.
The error that the trace shows:
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/uti
ls/simplejson/__init__.py", line 111, in <module>
import simplejson
File "/usr/local/lib/python2.7/site-packages/simplejson-2.3.0-py2.7-linux-x86_
64.egg/simplejson/__init__.py", line 111, in <module>
from decoder import JSONDecoder, JSONDecodeError
MemoryError
Seems more a bug (memory leak) on Django or simplejson module reading your settings.py. The server1 has 8 GB of Ram and normally used 2-4 GB, so it is pretty weird that you receive a MemoryError exception.
Try again and keep me aware of you results. Soon Django 1.4 would be released so maybe we can update soon for fix this.
-
OK, as I mentioned previously the syncdb problem is gone and the database seems to work fine.
However, I can't get the project running. This is what I get in error log:
[Wed Mar 14 00:42:24 2012] [error] [client x.x.x.x] File "/home/monfloo/public_html/monfloo-landing/django.wsgi", line 9, in <module>
[Wed Mar 14 00:42:24 2012] [error] [client x.x.x.x] mod_wsgi (pid=32211): Exception occurred processing WSGI script '/home/monfloo/public_html/monfloo-landing/django.wsgi'.
[Wed Mar 14 00:42:24 2012] [error] [client x.x.x.x] mod_wsgi (pid=32211): Target WSGI script '/home/monfloo/public_html/monfloo-landing/django.wsgi' cannot be loaded as Python module.
[Wed Mar 14 00:42:24 2012] [error] [client x.x.x.x] File "/home/monfloo/public_html/monfloo-landing/django.wsgi", line 9, in <module>
[Wed Mar 14 00:42:24 2012] [error] [client x.x.x.x] mod_wsgi (pid=32211): Exception occurred processing WSGI script '/home/monfloo/public_html/monfloo-landing/django.wsgi'.
[Wed Mar 14 00:42:24 2012] [error] [client x.x.x.x] mod_wsgi (pid=32211): Target WSGI script '/home/monfloo/public_html/monfloo-landing/django.wsgi' cannot be loaded as Python module.
My django.wsgi:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
import os, sys, traceback
import django.core.handlers.wsgi
import psycopg2
filename = 'error_log.txt'
f = open(filename, 'w')
try:
sys.path.append('/home/monfloo/monfloo-lp/monfloo_lp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'monfloo_lp.settings'
os.environ['PYTHON_EGG_CACHE'] = '/home/monfloo/tmp/trac-eggs'
application = django.core.handlers.wsgi.WSGIHandler()
f.write('Ok')
except:
traceback.print_exc(file=f)
.htaccess:
Options ExecCGI
Options +FollowSymLinks
SetHandler wsgi-script
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(django.wsgi)
RewriteRule ^(.*)$ django.wsgi/$1 [L]
I checked whether wsgi is working by testing the solution found on http://groups.google.com/group/django-users/browse_thread/thread/45bf45ec14bab5dd/b7bfcc750ff9de14 as well as yours, from http://quijost.com/foro/desarrollo-web/ejemplo-de-prueba-index-py-para-django-y-mysql-con-mod_wgsi/ - both work as expected.
Any idea what I have done wrong or what is missing?
-
Hi again Lwoo,
Sorry for the delay.
This appears on root error log:
[Wed Mar 14 00:57:15 2012] [error] [client XX.XX.XX.XX] mod_wsgi (pid=12662): Target WSGI script '/home/monfloo/public_html/monfloo-landing/django.wsgi' cannot be loaded as Python module.
[Wed Mar 14 00:57:15 2012] [error] [client XX.XX.XX.XX] mod_wsgi (pid=12662): Exception occurred processing WSGI script '/home/monfloo/public_html/monfloo-landing/django.wsgi'.
[Wed Mar 14 00:57:15 2012] [error] [client XX.XX.XX.XX] Traceback (most recent call last):
[Wed Mar 14 00:57:15 2012] [error] [client XX.XX.XX.XX] File "/home/monfloo/public_html/monfloo-landing/django.wsgi", line 9, in <module>
[Wed Mar 14 00:57:15 2012] [error] [client XX.XX.XX.XX] f = open(filename, 'w')
[Wed Mar 14 00:57:15 2012] [error] [client XX.XX.XX.XX] IOError: [Errno 13] Permission denied: 'error_log.txt'
[Wed Mar 14 00:57:15 2012] [warn] [client XX.XX.XX.XX] mod_include: Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed
Seems that you need set previously a the write permissions on error_log.txt and also complains about "Options +Includes"
Note too that sys.path.append('/home/monfloo/monfloo-lp/monfloo_lp') is wrong. You should put with public_html sys.path.append('/home/monfloo/public_html/monfloo-lp/')
-
I had CHMODed error_log.txt to 666, after your reply I changed it even to 777, but it's still empty. :-\ Switched back to 666.
Also, I modified my .htaccess as follows:
Options ExecCGI
Options +FollowSymLinks
Options +Includes
SetHandler wsgi-script
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(django.wsgi)
RewriteRule ^(.*)$ django.wsgi/$1 [L]
Moved the project from /home/monfloo/monfloo_lp to /home/monfloo/public_html/monfloo_lp and edited django.wsgi accordingly:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
import os, sys, traceback
import django.core.handlers.wsgi
import psycopg2
filename = 'error_log.txt'
f = open(filename, 'w')
try:
sys.path.append('/home/monfloo/public_html/monfloo-lp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'monfloo_lp.settings'
os.environ['PYTHON_EGG_CACHE'] = '/home/monfloo/tmp/trac-eggs'
application = django.core.handlers.wsgi.WSGIHandler()
f.write('Ok')
except:
traceback.print_exc(file=f)
However, still no success - it keeps on complaining that "Target WSGI script '/home/monfloo/public_html/monfloo-landing/django.wsgi' cannot be loaded as Python module.", just as if nothing has been modified. :(
-
I will check this for try to find a solution, but it could be that a owner file permissions. I mean user/group options as running as apache (nobody/nobody). And Django runs then as Apache application too handled by ws-script
But write a file should could make easily, because Django write files without problems but no running as apache user (nobody/nobody).
You could try use logging module or even more advanced solutions for fetch the exceptions:
http://www.davidcramer.net/code/502/debugging-django-errors.html
http://lucumr.pocoo.org/2007/5/21/getting-started-with-wsgi
-
I applied the hint from one of the links from your previous post and now I get all the tracebacks into my mailbox. I keep on getting the same error (the following lines are the most interesting):
File "/home/monfloo/public_html/monfloo-landing/monfloo_lp/urls.py", line 6, in <module>
admin.autodiscover()
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/contrib/admin/__init__.py", line 22, in autodiscover
mod = import_module(app)
File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named mailing
"mailing" is the name of app which I use in my project. I tried editing paths in settings.py but it didn't solve the problem. Also, error_log states:
[Wed Mar 14 22:42:23 2012] [error] [client x.x.x.x] File "/home/monfloo/public_html/monfloo-landing/monfloo_lp/urls.py", line 6, in <module>
[Wed Mar 14 22:42:23 2012] [error] [client x.x.x.x] mod_wsgi (pid=21285): Exception occurred processing WSGI script '/home/monfloo/public_html/monfloo-landing/django.wsgi'
line 6 in urls.py is admin.autodiscover(). Still no idea. :/
-
Hi Lwoo,
Entering to http://monfloo.quijost.com/monfloo-landing/ appear this on general error log:
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] mod_wsgi (pid=24275): Exception occurred processing WSGI script '/home/monfloo/public_html/django.wsgi'.
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] Traceback (most recent call last):
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/core/handlers/wsgi.py", line 272, in __call__
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] response = self.get_response(request)
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/core/handlers/base.py", line 153, in get_response
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/core/handlers/base.py", line 218, in handle_uncaught_exception
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] return callback(request, **param_dict)
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/utils/decorators.py", line 93, in _wrapped_view
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] response = view_func(request, *args, **kwargs)
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/views/defaults.py", line 30, in server_error
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] t = loader.get_template(template_name) # You need to create a 500.html template.
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/template/loader.py", line 157, in get_template
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] template, origin = find_template(template_name)
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] File "/usr/local/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/template/loader.py", line 138, in find_template
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] raise TemplateDoesNotExist(name)
[Thu Mar 15 10:54:22 2012] [error] [client XX.XX.XX.XX] TemplateDoesNotExist: 500.html
So, you are getting a exception TemplateDoesNotExist. Try checking the current paths on django project and catch the exception when you import the template.