views:

357

answers:

3

Hello,

I am running Django with mod_python on a Red Hat Linux box in production. A little while ago, for a reason unknown to me, the admin stopped working, throwing a 500 error. The error is as follows:

ValueError at /admin/
Empty module name
Request Method: GET
Exception Type: ValueError
Exception Value: 
Empty module name
Exception Location: /usr/local/lib/python2.6/site-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.6.2

Has anyone encountered this before? I have absolutely no idea how to fix this problem.

Thank you for any help.

+1  A: 

Here's what my importlib.py looks like:

def import_module(name, package=None):
    """Import a module.

    The 'package' argument is required when performing a relative import. It
    specifies the package to use as the anchor point from which to resolve the
    relative import to an absolute import.

    """
    if name.startswith('.'):
        if not package:
            raise TypeError("relative imports require the 'package' argument")
        level = 0
        for character in name:
            if character != '.':
                break
            level += 1
        name = _resolve_name(name[level:], package, level)
    __import__(name)
    return sys.modules[name]

Line 35 is this: __import__(name). So I would do two things: modify the code so that you print name and I'd run this Django app under the development web server. Then you can find out what the code is trying to import. That might give you a clue as to what changed.

Also, you might get a better stack trace with that approach.

hughdbrown
A: 

The problem fixed itself. Thanks for the help anyway.

mjaz
how? did you just restart the server?
hasen j
I used to believe that problems fixed themselves. Then I found it was worthwhile to figure out what the cause was.
hughdbrown
I restarted the server and double checked the settings file. I went to the admin today, and it showed up. If it occurs again, I'll delve deeper into it, but until then, my client is content.
mjaz
A: 

I was just debugging this problem. The error arises when Django is attempting to set up the template context processors, and the root cause was a definition which should have been a tuple but was actually a string.

This is what I had in my config file:

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth'
)

This is what I should have had:

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
)

Without the trailing comma, Python treats the value of the variable as a string. Thus, Django code which looks like this:

for path in settings.TEMPLATE_CONTEXT_PROCESSORS:
    i = path.rfind('.')
    module,attr = path[:i],path[i+1:]

the first value of 'path' is 'd', not 'django.core.context_processors.auth'. This leads the value of 'i' to be -1 and thus the value of 'module' to be empty.

Make sure that all of the tuple-like things in your Django config are actually tuples, which means if they have a single value, they still need a trailing comma.

Joe Germuska