Python + Django + Passenger


#1

After over 24 hours and not receiving a response from DreamHost support for the ticket I submitted, I cancelled the ticket and just started playing around trying to do it myself. I was able to setup my site.dreamhosters.com after a bad url was registered with my account. I am now unable to get Passenger running properly with my Python 2.7.5 & Django 1.5.1.

I keep getting a 500 internal error and logging doesn’t seem to be telling me why.

import sys, os
log = file('/home/username/site.dreamhosters.com/passenger_wsgi.log', 'a')
print >>log, "Running %s" % (sys.executable)
cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(cwd + '/public/GearTracker')  #You must add your project here or 500
sys.path.append(cwd + '/public')
#Switch to new python
#You may try to replace $HOME with your actual path
if sys.version < "2.7.5":
	os.execl("/home/username/env/bin/python","python2.7.5", *sys.argv)
sys.path.insert(0,'/home/username/env/bin')
sys.path.insert(0,'/home/username/env/lib/python2.7/site-packages/django')
sys.path.insert(0,'/home/username/env/lib/python2.7/site-packages')
sys.path.insert(0,'/home/username/site.dreamhosters.com/public')
sys.path.insert(0,'/home/username/site.dreamhosters.com/public/GearTracker')
os.environ['DJANGO_SETTINGS_MODULE'] = "GearTracker.settings"
import django.core.handlers.wsgi
try:
	application = django.core.handlers.wsgi.WSGIHandler()
	log.flush()
except Exception, inst:
	print >>log, "Error: %s" % str(type(inst))
	print >>log, inst.args
	log.flush()
finally:
	log.close()

passenger_wsgi.log

error.log

[Wed May 22 09:13:30 2013] [error] [client IP] Premature end of script headers: [Wed May 22 09:13:30 2013] [error] [client IP] Premature end of script headers: internal_error.html

folder structure -username/ ----site.dreamhosters.com/ ------passenger_wsgi.py ------passenger_wsgi.log ------public/ --------GearTracker/ ----------settings.py ----------url.py ----------etc... --------inventory/ --------accounts/ --------static/ --------wsgi/ --------templates/ --------manage.py

This is my first django site setup on a server without using Heroku. How do I get my site to load? I use PyCharm and that IDE setup my folder structure like this.


#2

Can you PM me (email button at the bottom of my post) with the URL of your site? I can take a look at some server logs to try and figure out what’s going on here but I’ll need to know where it is first.


#3

Okay, got your message — here’s the error message you weren’t able to see before:

File "/dh/passenger/lib/phusion_passenger/wsgi/request_handler.py", line 59, in main_loop self.process_request(env, input_stream, client) File "/dh/passenger/lib/phusion_passenger/wsgi/request_handler.py", line 164, in process_request result = self.app(env, start_response) File "/home/username/env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in __call__ self.load_middleware() File "/home/username/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 51, in load_middleware mod = import_module(mw_module) File "/home/username/env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/home/username/env/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 3, in <module> from django.contrib.auth.backends import RemoteUserBackend File "/home/username/env/lib/python2.7/site-packages/django/contrib/auth/backends.py", line 3, in <module> from django.contrib.auth.models import Permission File "/home/username/env/lib/python2.7/site-packages/django/contrib/auth/models.py", line 8, in <module> from django.db import models File "/home/username/env/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module> backend = load_backend(connection.settings_dict['ENGINE']) File "/home/username/env/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "/home/username/env/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__ backend = load_backend(db['ENGINE']) File "/home/username/env/lib/python2.7/site-packages/django/db/utils.py", line 27, in load_backend return import_module('.base', backend_name) File "/home/username/env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/home/username/env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module> raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) <class 'django.core.exceptions.ImproperlyConfigured'>: Error loading MySQLdb module: No module named MySQLdb

It looks as though you don’t have MySQLdb set up in your virtualenv. You’ll need to install it.


#4

doh~! thank you for helping and the fast reply! thought I had those installed!


#5

The answer to this would have been useful to the entire forum…


#6

Don’t know what you mean… He stated what the issue was. MySQLdb was not installed as a package…


#7

error.log

[Wed May 22 09:13:30 2013] [error] [client IP] Premature end of script headers: [Wed May 22 09:13:30 2013] [error] [client IP] Premature end of script headers: internal_error.html

The error log is as useful as tits on a bull.


#8

I have a very similar issue, but I do have MySQL installed and Django is working properly.

My issue is that Django isn’t using Python 2.7.5 which I have installed on my account. As soon as I add the following lines to my passenger_wsgi.py file, I get a 500 server error and log errors are the usual unhelpful “Premature end of script headers.”

INTERP = "/home/egeyer/opt/bin/python2.7"
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)

I know python is installed and working correctly in that location.

Any help is much appreciated!

  • Erin
    [hr]
    I have also tried “/home/egeyer/opt/bin/python” as the location and still the same 500 error.
    [hr]
    Ok! I just figured it out myself… I had not installed MySQL-python… I thought I had, but I guess I had only downloaded and unpacked it and never gone through with installation, so I did and now Django is running the correct python version.

#9

I have exactly the same issue as the original poster. I get those cryptic “Premature end of script headers” messages in my error log but no more information about the real issues causing them.

How can I see the error logs that show the real issue? That is the question that was left unanswered.

(I have MySQLdb installed so that’s not the issue.)

Thanks,
Dimitris