New python web app not working?

October 18, 2016

How many times have you had the thrill of releasing a new service or app to the world, only to have it crashing down when you test the URL and find a server error page instead of your work? Here are a few tips I use when I’m trying to figure out why the new python service I have set up is not working:

Check server logs

Many times, there’s an error with the Apache config file. There’s no guarantee that it’ll show up in the logs, but it’s a great place to start.

Thanks go out to Benoit Bernard, who let me know that on *nix servers, there’s a global log at /var/log/message , and a journalctl command that lets a privileged user to view it. This should probably be the easiest method to figure out what’s going on.

On the servers I’ve been using at work and for play, my user account is not privileged enough to view that log. Instead, I find my issues by:

Create a python log

If it seems everything is working well from your server configuration, set up a temporary log in your file that handles the wsgi connection. Below is an example of a logger for a django app. Bold text shows the logging additions.

import logging
logging.basicConfig(filename="/path/to/newapp.log", level=logging.DEBUG)

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings.production")

application = get_wsgi_application()

Opening a new terminal window and typing tail -f /path/to/newapp.log will give you a view into what’s going on.

Sadly, this doesn’t always provide a clear pointer to what’s going on, but it’s a great place to start.

And if you ever get an issue where the service is complaining that something is wrong in one of python’s core modules, triple check that your Apache application folder is set to accept traffic.

Require all granted

Do you have any other tips that work better than these? Please let me know!

Read other articles

Subscribe for email updates

© 2020 Everyday Superpowers