2

I was trying to deploy django on a shared webhost which is not django specific. Host offers old version of python installed, but since I have ssh access ability, I've managed to extend python installation with modules I need (including django) by installing them locally in my home folder. Ok, so I've created django project, did tweaks that needed to do (setting up PYTHONPATH and PATH globals etc.), made django.fcgi script which starts django and did ./django.fcgi from shell. This is the response:

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Traceback (most recent call last):
  File "/home/tentacle/lib/python2.4/site-packages/flup-1.0.3.dev_20110405-py2.4.egg/flup/server/fcgi_base.py", line 574, in run
    protocolStatus, appStatus = self.server.handler(self)
  File "/home/tentacle/lib/python2.4/site-packages/flup-1.0.3.dev_20110405-py2.4.egg/flup/server/fcgi_base.py", line 1159, in handler
    result = self.application(environ, start_response)
  File "/home/tentacle/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 272, in __call__
    response = self.get_response(request)
  File "/home/tentacle/lib/python2.4/site-packages/django/core/handlers/base.py", line 169, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/tentacle/lib/python2.4/site-packages/django/core/handlers/base.py", line 202, in handle_uncaught_exception
    from django.views import debug
  File "/home/tentacle/lib/python2.4/site-packages/django/views/debug.py", line 9, in <module>
    from django.template import (Template, Context, TemplateDoesNotExist,
  File "/home/tentacle/lib/python2.4/site-packages/django/template/__init__.py", line 53, in <module>
    from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END,
MemoryError
Status: 500 Internal Server Error
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>Unhandled Exception</title>
</head><body>
<h1>Unhandled Exception</h1>
<p>An unhandled exception was thrown by the application.</p>
</body></html>

So, I'm aware that this issue is about limited memory for my user (wrong?), but is it so low that I cannot run bare django? Just for things to be worse, a month ago the same provider gave me a test account, and a was able not just to run django, but to install locally newer version of python and run it nice. I did asked my web host support for help, but I didn't got any usable answer. Also since they are resellers I'm not very sure how much they help.

Is there a way to overcome this problem? Any suggestion is welcome.

Thanks in advance

-----------------------------------Update--------------------------------------------------

#!/home/<username>/bin/python
import os, sys

sys.path.insert(0, "/home/<username>/djangoprojects")
sys.path.insert(0, "/home/<username>/djangoprojects/testproject")
os.environ['PATH']= "/home/<username>/bin:"+os.environ['PATH']

os.environ['DJANGO_SETTINGS_MODULE'] = 'testproject.settings'

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

This is how look like my configuration. I must admit that there was a little error (interpreter path), but 'settings' file path was good.

After correcting the interpreter path to right one, First I've got StringError (some triple quoted doc string in one of djangos files was not closed - hm, hardly), than in next run MemoryError, and again MemoryError and so on. After a while (an hour) I tried to execute script again (no further changes made) and constantly ending up with Segmentation fault (core dumped).

Any suggestions?

  • 1
    Why are you sure it is about limited memory? The first four lines mention missing parameters. That said, do the answers http://stackoverflow.com/questions/800584/wsgiserver-errors-when-trying-to-run-django-app or http://stackoverflow.com/questions/2526172/settings-module-not-found-deploying-django-on-a-shared-server do anything for you? – jro Oct 18 '11 at 09:21
  • Thx for reply. The four missing parameters causes the fact that the script was triggered from the shell instead as regular browser request. Still, it must give me proper response which in this case should be django success page. – Nikola Trbojevic Oct 19 '11 at 06:31

1 Answers1

0

When running it from the command line, you need to specify the Django parameters explicitly. Assuming you are running the script from the same folder as your settings.py is in:

import os, sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

# ... rest of your startup script...

Also, check if your .htaccess file still has a correct RewriteRule to your .fcgi script.

jro
  • 9,300
  • 2
  • 32
  • 37
  • I've made an update on my question. Can You help me some more? Thanks. – Nikola Trbojevic Oct 21 '11 at 12:57
  • @NikolaTrbojevic: I'm a bit uncertain on this. I've never deployed Django in such an environment, but the Django book has a [chapter dedicated to deployment](http://www.djangobook.com/en/2.0/chapter12/). Look for the paragraphs "Handling a Segmentation Fault" and "Running Django on a Shared-Hosting Provider with Apache". I don't know if you've read that already, but maybe there you'll find some possible answers. – jro Oct 24 '11 at 06:43