2

I was using Django site on local machine with Ubuntu and have just uploaded but getting 500 internal server error and I am unable to understand the reason.

Seems like it is unable to see some modules, may be it is not looking at my settings file? The following is the error log for this issue, may be that reveal what is happening:

    [Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10] mod_wsgi (pid=23248): Exception occurred processing WSGI script '/var/www/kaasib/pypr$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10] Traceback (most recent call last):
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 24$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     response = self.get_response(request)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 17$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 22$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return debug.technical_500_response(request, *exc_info)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 66, in te$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     html = reporter.get_traceback_html()
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 276, in g$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return t.render(c)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 140, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return self._render(context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 134, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return self.nodelist.render(context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 823, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     bit = self.render_node(node, context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 74, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return node.render(context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 84, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     output = self.filter_expression.resolve(context)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 599, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     new_obj = func(obj, *arg_vals)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/template/defaultfilters.py", li$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return format(value, arg)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 310,$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return df.format(format_string)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 33, $
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     pieces.append(force_unicode(getattr(self, piece)()))
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 214,$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return self.format('D, j M Y H:i:s O')
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 33, $
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     pieces.append(force_unicode(getattr(self, piece)()))
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/encoding.py", line 71, in$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     s = unicode(s)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 121,$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return func(*self.__args, **self.__kw)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py",$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return _trans.ugettext(message)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     return do_translate(message, 'ugettext')
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     _default = translation(settings.LANGUAGE_CODE)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     default_translation = _fetch(settings.LANGUAGE_CODE)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     app = import_module(appname)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]   File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, i$
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10]     __import__(name)
[Sat Dec 29 02:59:37 2012] [error] [client 139.190.233.10] ImportError: No module named company

Here is content of httpd.conf file:

WSGIPythonPath /var/www/kaasib/pyproject/kaasib/

<Directory /var/www/kaasib/pyproject/kaasib/kaasib/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

WSGISCRIPTAlis line is in vhost file that is in site-available. And following is content of wsgi file:

"""
WSGI config for kaasib project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kaasib.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
halfer
  • 19,824
  • 17
  • 99
  • 186
Hafiz
  • 4,187
  • 12
  • 58
  • 111

3 Answers3

1

It would be helpful to see your apache conf file and you wsgi conf file for your app.

As you suggested it looks like your company module is not found. That could be because of many reasons. I would start by checking your WSGIPythonPath and making sure it includes your app.

Take a look at the Django WSGI deployment guide for more details.

  • I have attached the content of wsgi file and httpd.conf above and updated my question, please check that – Hafiz Dec 29 '12 at 00:38
1

It seems to me that your project is not in your pythonpath. Try adding this at the top of your wsgi.py and see how it goes:

import os, sys

path = '/path-to/your/project-root/'
if path not in sys.path:
   sys.path.append(path)
ppetrid
  • 3,745
  • 27
  • 29
  • should I append this code at the top of wsgi.py in my project, and it is somepath/projectname/projectname/wsgi.py , so should I point out it at somepath/projectname/projectname or somepath/projectname/ ? – Hafiz Dec 29 '12 at 15:35
  • Ok, if I understand correctly you use django >= 1.4, so it's 'somepath/projectname/' (ie. the directory containing your django apps , for example 'somepath/projectname/company' should be a valid path) – ppetrid Dec 29 '12 at 17:09
  • welcome, it's a common problem I've learned the hard way in my own projects :) – ppetrid Dec 30 '12 at 02:18
0

Did you install the module on the remote server via pip or some some other means? It simply cannot find the module names company.Also make sure that you include "Company" module in your installed INSTALLED_APPS in your settings file.

shaytac
  • 3,789
  • 9
  • 36
  • 44
  • it is INSTALLED_APPS in my settings file but don't know if it really reading my settings file – Hafiz Dec 29 '12 at 00:32