This appears to be the first point at which the database is accessed.

|email_object = Email.objects.get(email=kwargs['email'])|

I would print out some of the settings values before that point to make
sure you're actually using the settings file you intend to use. E.g:

from django.conf import settings
print settings.DATABASES

_Nik

On 6/11/2012 6:47 AM, Group Mail wrote:
> Hi,
>
> ---
>
> Preliminary Note: For nicer formatting of the code snippets in this
> email, you can check out the stack overflow post I made asking this
> question,
>
> http://stackoverflow.com/questions/10881249/django-database-improperly-configured-when-function-called-outside-of-django
>
> ---
>
> I'm trying to call a python function that makes some queries into my
> django database from GNU mailman.
>
> When mailman tries to deliver a message, it imports my python script.
> It later calls a function in my script to modify the message object.
> The error I'm getting is:
>
> ImproperlyConfigured: settings.DATABASES is improperly configured.
> Please supply the ENGINE value. Check settings documentation \
> for more details.
>
> Here's how I'm configuring the settings, at the very top of my file:
>
> from django.core.management import setup_environ
> from mysite import settings
> setup_environ(settings)
>
> When I run python manage.py syncdb, it seems to create the database
> fine. Here's my database configuration:
>
> DATABASES = {
>     'default': {
>         'ENGINE': 'django.db.backends.mysql',  # Add
> 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
>         'NAME': 'django_db',                      # Or path to
> database file if using sqlite3.
>         'USER': 'root',                      # Not used with sqlite3.
>         'PASSWORD': 'root',                  # Not used with sqlite3.
>         'HOST': '',                      # Set to empty string for
> localhost. Not used with sqlite3.
>         'PORT': '',                      # Set to empty string for
> default. Not used with sqlite3.
>     }
> }
>
> Further, I've commented out the entirety of my function such that it
> now looks like:
>
> def f():
>     return
>
> So I don't think this has to do with the function call.
>
> Further, I've tested the setup_environ lines in the python console and
> everything works as expected.
>
> Further, when I restart GNU mailman, I believe it has to load all its
> scripts, which means it necessarily has to import my file. This means
> that these "setup_environ" lines run when I restart mailman. And it's
> fine -- I get no errors.
>
> It's only when GNU mailman tries to deliver a message that I have problems.
>
> So I'm pretty stumped. I do run the mailman restart command as sudo
> with additional PYTHONPATH and DJANGO_SETTINGS_MODULE environmental
> variables, but I've manually added to the relevant parts to my
> sys.path and os.environ dict, which doesn't fix the problem either.
> Besides, the error doesn't suggest it's a problem with the path or
> being unable to find the settings module.
>
> Thanks!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to