Jump to content

Django Error 500


Recommended Posts

Hi,

 

I'm trying to deploy a Django website on Tommy, deployed in /home/arvy/public_html/stantoine, associated with the domain http://dev.centrestantoine.heliohost.org (subdomain alias).

 

I get an error 500. I'm pretty sure my .htaccess configuration is right, because it returns a 404 error if I comment all the lines of this file.

 

I was trying to add a try/catch block to display the error message, and sort it out by myself, but I realize that even a simple hello world block doesn't work:

 

def application(environ, start_response):
status = '200 OK'
output = 'Hello World!\n'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]

 

I'm rather new in Python, so maybe I'm wrong with something. Any idea about the error 500 that occurs when trying to play that?

The following code works on a local Apache + embedded WSGI configuration. Also, the standard code (what is currently commented in the dispatch.wsgi file) also works locally.

 

Thanks for your help!

Link to comment
Share on other sites

Hi Krydos,

 

Well, my question was not really related to Django but to WSGI solely.

But yes, I followed the guide and it worked. With my project, I can fall on a Django message stating that there are no route patterns, if I empty the "urls.py" file. So I consider that the Django setup is correct.

 

Now, I have other errors 500 and would like to be able to know what's behind without pinging you every two minutes. The reason why I tried to put a try/except block (as described at the bottom of this Heliohost wiki page: http://wiki.helionet.org/Solving_Internal_Server_Errors)

But the "except" code doesn't seem to work. And even a simple WSGI hello world doesn't (error 500, I don't know what's behind).

 

What I do on my side goes a little beyond running Django, because I also try to run DjangoCMS (by embedding the Python libs in the project). For that, I reproduced your setup (well something close) on a Docker image, and the project worked locally. But I get the error 500 on Heliohost, so I would like to catch the exceptions to know what is different with my Docker container.

 

Thanks for your help!

Edited by arvy
Link to comment
Share on other sites

Here's your /home/arvy/public_html/stantoine/.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(stantoine/dispatch\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ stantoine/dispatch.wsgi/$1 [QSA,PT,L]
The line for dispatch.wsgi starts from the webroot which is public_html. So according to the .htaccess it looks for /home/arvy/public_html/stantoine/dispatch.wsgi and it can't find it there because it's actually one directory deeper in /home/arvy/public_html/stantoine/stantoine/dispatch.wsgi That's fine and it matches the structure that running the startproject command on your home computer creates. So, try changing your /home/arvy/public_html/stantoine/.htaccess to this

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(stantoine/dispatch\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ stantoine/stantoine/dispatch.wsgi/$1 [QSA,PT,L]
Link to comment
Share on other sites

Thanks for the answer Krydos

 

But adding a stantoine segment to the URL doesn't give better results.

 

Also, I defined a subdomain:

dev.centrestantoine.heliohost.org /public_html/stantoine

So I was expecting the .htaccess to be relative to the /public_hmtl/stantoine directory. Also I had the feeling the .htaccess was fine because I get the right Django messages when I call the dispatcher instead of the hello world.

 

For now I'll create a new subdomain a do some tests with the Django sample... I'll be happy when I'll make this helloworld work. Currently, I get a DNS error on both subdomains, I suppose I have to wait for them to be propagated.

 

I notice also that you added the python 3.6 missing shebang, I thought about it recently, maybe that's the reason why things didn't behave as I expected. Well, thanks for the help so far, I'll try to understand some things with the test subdomain by myself and post again if I feel I have no more things to experiment with.



Woops! The DNS not responding is due to the fact I'm dumb :)

I'm often typing heliohost.com instead of heliohost.org...

Link to comment
Share on other sites

Ok, figured it out!

 

My issue was that I had to convert to ASCII the output.

 

The following dispatcher code block works quite well and outputs the errors:

#!/usr/bin/python3.6

import os, sys, logging

application = None

try:
    dirName = os.path.abspath(os.path.dirname(__file__) + '/..')
    sys.path.insert(1, dirName)
    sys.path.insert(1, dirName + "/libs")

    from django.core.wsgi import get_wsgi_application
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "stantoine.settings")
    application = get_wsgi_application()
except Exception as e:
    err = e
    def _application(env, start_response):
        global err
        start_response('200 OK', [('Content-Type','text/html')])
        return [b"Error: ", str(err).encode('ascii')]

    application = _application

I do sys.path.insert to use my own libraries before the global ones... I'm trying to use python packages that I copied in my project libs directory. Of course, it would fail for binaries. However it works with the container ndegardin/apache-wsgi:django I created to experiment with that: https://hub.docker.com/r/ndegardin/apache-wsgi/tags/ (that's an Alpine, but it has all the python extensions listed on your https://krydos.heliohost.org/cgi-bin/modules36.py page).

 

Now, I can tell that my error is:

Error: libjpeg.so.8: cannot open shared object file: No such file or directory

It is related to the Python package Pillow, which needs the libjpeg, libpng, libjpeg-dev, libpng-dev, and zlib packages (maybe the names are bit different on the Heliohost Linux distribution)...

So... would it be possible to have the python Pillow >=3.0 package installed, with its required libraries? Should I open a different post?

 

Thanks!

Edited by arvy
Link to comment
Share on other sites

Also, I defined a subdomain: dev.centrestantoine.heliohost.org So I was expecting the .htaccess to be relative to the /public_hmtl/stantoine directory.

Yes, you're right. You don't need the double stantoine if accessed from the subdirectory since that moves the webroot. I didn't realize you were using a subdomain so this would have caused a 500 error if you were using your main domain like I assumed.

 

So... would it be possible to have the python Pillow >=3.0 package installed, with its required libraries?

Python pillow 4.2.1 installed on Tommy version 3.6.0 /usr/bin/python3.6 https://krydos.heliohost.org/cgi-bin/modules36.py

 

I notice also that you added the python 3.6 missing shebang, I thought about it recently, maybe that's the reason why things didn't behave as I expected.

You actually don't need a shebang for django or flask. Even if you put the shebang of python 2.7 it would just ignore it and use 3.6 anyways. You don't even need the files to be executable; 644 suffices.
Link to comment
Share on other sites

You rock, Krydos!

The website with DjangoCMS is now working! (well to run correctly I have to lower the number of MySQL connections it needs or make SQLite work, but it's a different subject)

Thanks for the help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...