Python Forum

Full Version: Django+uWsgi unable to find "application" callable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

I am running askbot via uWsgi, which was working fine.
But after few thing updated (maybe uWsgi from 2.0.14 to 2.0.15), it is stopped. Please help.

The versions:

Python 2.7.13
Django (1.8.17)
uWSGI (2.0.15)

The problem from uWsgi startup log:

Error:
*** Operational MODE: single process *** handling WSGI exception unable to find "application" callable in file /foo/askbot1/django.wsgi unable to load app 0 (mountpoint='') (callable not found or import error) *** no app loaded. going in full dynamic mode ***
The uWsgi configuration:

Quote:[uwsgi]

# Django-related settings
# the base directory (full path)
chdir = /foo/askbot1
# Django's wsgi file
wsgi-file = /foo/askbot1/django.wsgi

# the virtualenv (full path)
home = /bar/.virtualenvs/askbot010

# process-related settings
# master
master = true
# maximum number of worker processes
processes = 1

logto = /foo/askbot1/log/askbot.log

# the socket (use the full path to be safe)
socket = /foo/askbot1/site.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666

# clear environment on exit
vacuum = true

The django.wsgi file:

import os
import sys
import time
import traceback
import signal

current_directory = os.path.dirname(__file__)
parent_directory = os.path.dirname(current_directory)
module_name = os.path.basename(current_directory)

sys.path.append(parent_directory)
sys.path.append(current_directory)
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % module_name

from django.core.wsgi import get_wsgi_application
try:
    application = get_wsgi_application()
    print 'WSGI without exception'
except Exception:
    print 'handling WSGI exception'
    # Error loading applications
    if 'mod_wsgi' in sys.modules:
        traceback.print_exc()
        os.kill(os.getpid(), signal.SIGINT)
        time.sleep(2.5)
(Aug-23-2017, 02:32 PM)rosettas Wrote: [ -> ]
Error:
*** Operational MODE: single process *** handling WSGI exception unable to find "application" callable in file /foo/askbot1/django.wsgi
Quote:
from django.core.wsgi import get_wsgi_application
try:
    application = get_wsgi_application()
    print 'WSGI without exception'
except Exception:
    print 'handling WSGI exception'

wsgi works by looking for a callable object that's specifically named "application".  The error is telling you that it can't find that variable name.  And yet, you clearly are defining it. 

django.core.wsgi is not complicated:
https://github.com/django/django/blob/ma...re/wsgi.py Wrote:
import django
from django.core.handlers.wsgi import WSGIHandler


def get_wsgi_application():
    """
    The public interface to Django's WSGI support. Return a WSGI callable.
    Avoids making django.core.handlers.WSGIHandler a public API, in case the
    internal WSGI implementation changes or moves in the future.
    """
    django.setup(set_prefix=False)
    return WSGIHandler()

Try replacing your error handling to print out the raw error:
except Exception as err:
    print(err)
Maybe we can get more info that way. I'm not sure what else to do, as everything appears to be setup correctly, and the error doesn't make sense with the file you've shared.
Thanks! It works.

The raw error printing shows one postgresql lib lost. I have reinstalled the postgresql client, the problem solved.
Thanks for reporting back :)