graphite-web: Problem 0.9.x, Exception occurred processing WSGI script '/opt/graphite/conf/graphite.wsgi'

Hello everyone!

I’m trying to install the branch 0.9.x, but i’m getting the following error:

[Mon Feb 22 01:28:11.077967 2016] [wsgi:error] [pid 112:tid 140390432941952] mod_wsgi (pid=112): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.
[Mon Feb 22 01:28:11.078024 2016] [wsgi:error] [pid 112:tid 140390432941952] mod_wsgi (pid=112): Exception occurred processing WSGI script '/opt/graphite/conf/graphite.wsgi'.
[Mon Feb 22 01:28:11.078069 2016] [wsgi:error] [pid 112:tid 140390432941952] Traceback (most recent call last):
[Mon Feb 22 01:28:11.078181 2016] [wsgi:error] [pid 112:tid 140390432941952]   File "/opt/graphite/conf/graphite.wsgi", line 32, in <module>
[Mon Feb 22 01:28:11.078316 2016] [wsgi:error] [pid 112:tid 140390432941952]     application = DjangoWhiteNoise(application)
[Mon Feb 22 01:28:11.078339 2016] [wsgi:error] [pid 112:tid 140390432941952]   File "/usr/local/lib/python2.7/site-packages/whitenoise/django.py", line 46, in __init__
[Mon Feb 22 01:28:11.080182 2016] [wsgi:error] [pid 112:tid 140390432941952]     self.configure_from_settings(settings)
[Mon Feb 22 01:28:11.080255 2016] [wsgi:error] [pid 112:tid 140390432941952]   File "/usr/local/lib/python2.7/site-packages/whitenoise/django.py", line 68, in configure_from_settings
[Mon Feb 22 01:28:11.080328 2016] [wsgi:error] [pid 112:tid 140390432941952]     getattr(settings, 'STATIC_URL', ''))
[Mon Feb 22 01:28:11.080350 2016] [wsgi:error] [pid 112:tid 140390432941952]   File "/usr/local/lib/python2.7/site-packages/whitenoise/django.py", line 36, in get_prefix_from_url
[Mon Feb 22 01:28:11.080383 2016] [wsgi:error] [pid 112:tid 140390432941952]     return format_prefix(urlparse.urlparse(url).path)
[Mon Feb 22 01:28:11.080403 2016] [wsgi:error] [pid 112:tid 140390432941952]   File "/usr/local/lib/python2.7/urlparse.py", line 143, in urlparse
[Mon Feb 22 01:28:11.080709 2016] [wsgi:error] [pid 112:tid 140390432941952]     tuple = urlsplit(url, scheme, allow_fragments)
[Mon Feb 22 01:28:11.080740 2016] [wsgi:error] [pid 112:tid 140390432941952]   File "/usr/local/lib/python2.7/urlparse.py", line 182, in urlsplit
[Mon Feb 22 01:28:11.080778 2016] [wsgi:error] [pid 112:tid 140390432941952]     i = url.find(':')
[Mon Feb 22 01:28:11.080810 2016] [wsgi:error] [pid 112:tid 140390432941952] AttributeError: 'NoneType' object has no attribute 'find'

I used all the example files, only editing virtual host for apache

# This needs to be in your server's config somewhere, probably
# the main httpd.conf
# NameVirtualHost *:80

# This line also needs to be in your server's config.
# LoadModule wsgi_module modules/mod_wsgi.so

# You need to manually edit this file to fit your needs.
# This configuration assumes the default installation prefix
# of /opt/graphite/, if you installed graphite somewhere else
# you will need to change all the occurances of /opt/graphite/
# in this file to your chosen install location.

<IfModule !wsgi_module.c>
    LoadModule wsgi_module modules/mod_wsgi.so
</IfModule>

# XXX You need to set this up!
# Read http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGISocketPrefix
WSGISocketPrefix /var/run/apache2/wsgi

<VirtualHost *:80>
        ServerName graphite
        DocumentRoot "/opt/graphite/webapp"
        ErrorLog /opt/graphite/storage/log/webapp/error.log
        CustomLog /opt/graphite/storage/log/webapp/access.log common

        # I've found that an equal number of processes & threads tends
        # to show the best performance for Graphite (ymmv).
        WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120
        WSGIProcessGroup graphite
        WSGIApplicationGroup %{GLOBAL}
        WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL}

        # XXX You will need to create this file! There is a graphite.wsgi.example
        # file in this directory that you can safely use, just copy it to graphite.wgsi
        WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi

        # XXX To serve static files, either:
        # django-admin.py collectstatic --noinput --settings=graphite.settings
        # * Install the whitenoise Python package (pip install whitenoise)
        # or
        # * Collect static files in a directory by running:
        #     django-admin.py collectstatic --noinput --settings=graphite.settings
        #   And set an alias to serve static files with Apache:
        Alias /content/ /opt/graphite/webapp/content/
        <Location "/content/">
                SetHandler None
        </Location>

        # XXX In order for the django admin site media to work you
        # must change @DJANGO_ROOT@ to be the path to your django
        # installation, which is probably something like:
        # /usr/lib/python2.6/site-packages/django
        Alias /media/ "/usr/local/django/contrib/admin/media/"
        <Location "/media/">
                SetHandler None
        </Location>

        # The graphite.wsgi file has to be accessible by apache. It won't
        # be visible to clients because of the DocumentRoot though.
        <Directory /opt/graphite/conf/>
                Order deny,allow
                Allow from all
        </Directory>

</VirtualHost>

The script:

import os
import sys
sys.path.append('/opt/graphite/webapp')

try:
    from importlib import import_module
except ImportError:
    from django.utils.importlib import import_module

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'graphite.settings')  # noqa

from django.conf import settings
from django.core.wsgi import get_wsgi_application
from graphite.logger import log

application = get_wsgi_application()

try:
    import whitenoise
except ImportError:
    whitenoise = False
else:
    # WhiteNoise < 2.0.1 does not support Python 2.6
    if sys.version_info[:2] < (2, 7):
        whitenoise_version = tuple(map(
                int, getattr(whitenoise, '__version__', '0').split('.')))
        if whitenoise_version < (2, 0, 1):
            whitenoise = False

if whitenoise:
    from whitenoise.django import DjangoWhiteNoise
    application = DjangoWhiteNoise(application)
    prefix = "/".join((settings.URL_PREFIX.strip('/'), 'static'))
    for directory in settings.STATICFILES_DIRS:
        application.add_files(directory, prefix=prefix)
    for app_path in settings.INSTALLED_APPS:
        module = import_module(app_path)
        directory = os.path.join(os.path.dirname(module.__file__), 'static')
        if os.path.isdir(directory):
            application.add_files(directory, prefix=prefix)

# Initializing the search index can be very expensive. The import below
# ensures the index is preloaded before any requests are handed to the
# process.
log.info("graphite.wsgi - pid %d - reloading search index" % os.getpid())
import graphite.metrics.search  # noqa

I’m using python 2.7.11 on ubuntu 14 machine with apache 2.4.10.

Can someone help please?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 18 (8 by maintainers)

Most upvoted comments

@kennedyoliveira - You use WhiteNoise, don’t you? I tried, but it didn’t work so I turned it off. After sorting out /media alias I was fine.

It might be useful if you tell exactly what version of graphite you are installing. BTW. I noticed that Django 1.9.x is another problem.