This is almost definitely my own silly mistake somewhere, but it has
been driving me crazy for weeks now so thought I'd better check if
anyone else has come across it. Very intermittently (every couple of
days), I'll receive a Django error email containing something like
[1]. It is usually an ImportError, where <PROJECT_B>.wsgi has loaded
urls.py from <PROJECT_A> and tried to import an app from the other
project. Once or twice it has been an ImproperlyConfigured where
<PROJECT_B> has tried load middleware from <PROJECT_C>, etc. It occurs
with two particular projects most frequently, but they often swap, and
sometimes other projects get involved.

My httpd.conf can be found below [2]. I'm using mod_wsgi SVN. My
standard WSGI script is also provided [3].

Any ideas?

Thanks,
Simon


[1] Traceback (most recent call last):

 File "<HOME>/lib/django_1.2/django/core/handlers/base.py", line 91,
in get_response
   request.path_info)

 File "<HOME>/lib/django_1.2/django/core/urlresolvers.py", line 214, in resolve
   for pattern in self.url_patterns:

 File "<HOME>/lib/django_1.2/django/core/urlresolvers.py", line 243,
in _get_url_patterns
   patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

 File "<HOME>/lib/django_1.2/django/core/urlresolvers.py", line 238,
in _get_urlconf_module
   self._urlconf_module = import_module(self.urlconf_name)

 File "<HOME>/lib/django_1.2/django/utils/importlib.py", line 35, in
import_module
   __import__(name)

 File "<HOME>/webapps/django/<PROJECT_A>/urls.py", line 5, in <module>
   admin.autodiscover()

 File "<HOME>/lib/django_1.2/django/contrib/admin/__init__.py", line
20, in autodiscover
   mod = import_module(app)

 File "<HOME>/lib/django_1.2/django/utils/importlib.py", line 35, in
import_module
   __import__(name)

ImportError: No module named <APP_FROM_PROJECT_A>


<WSGIRequest
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'DOCUMENT_ROOT': '/etc/httpd/htdocs',
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_ACCEPT_ENCODING': 'identity',
 'HTTP_CONNECTION': 'Keep-Alive',
 'HTTP_HOST': '<PROJECT_B_DOMAIN>',
 'HTTP_USER_AGENT': 'Python-urllib/2.6',
 'HTTP_X_FORWARDED_FOR': '<CLIENT_IP>',
 'HTTP_X_FORWARDED_HOST': '<PROJECT_B_DOMAIN>',
 'HTTP_X_FORWARDED_SERVER': '<PROJECT_B_DOMAIN>',
 'PATH_INFO': u'/',
 'PATH_TRANSLATED': '<HOME>/webapps/django/<PROJECT_B>.wsgi/',
 'QUERY_STRING': '',
 'REMOTE_ADDR': '127.0.0.1',
 'REMOTE_PORT': '59766',
 'REQUEST_METHOD': 'GET',
 'REQUEST_URI': '/',
 'SCRIPT_FILENAME': '<HOME>/webapps/django/<PROJECT_B>.wsgi',
 'SCRIPT_NAME': u'',
 'SERVER_ADDR': '127.0.0.1',
 'SERVER_ADMIN': '<SERVER_ADMIN_EMAIL>',
 'SERVER_NAME': '<PROJECT_B_DOMAIN>',
 'SERVER_PORT': '80',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'SERVER_SIGNATURE': '',
 'SERVER_SOFTWARE': 'Apache',
 'mod_wsgi.application_group': '<PROJECT_B_DOMAIN>|',
 'mod_wsgi.callable_object': 'application',
 'mod_wsgi.handler_script': '',
 'mod_wsgi.input_chunked': '0',
 'mod_wsgi.listener_host': '',
 'mod_wsgi.listener_port': '<PORT_NUMBER>',
 'mod_wsgi.process_group': 'AEST',
 'mod_wsgi.request_handler': 'wsgi-script',
 'mod_wsgi.script_reloading': '1',
 'mod_wsgi.version': (4, 0),
 'wsgi.errors': <mod_wsgi.Log object at 0xa971cf0>,
 'wsgi.file_wrapper': <built-in method file_wrapper of
mod_wsgi.Adapter object at 0xa978458>,
 'wsgi.input': <mod_wsgi.Input object at 0xa971ed0>,
 'wsgi.multiprocess': False,
 'wsgi.multithread': True,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 1)}>



[2] httpd.conf:
ServerRoot "<HOME>/webapps/django/apache2"

LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule wsgi_module modules/mod_wsgi.so
LoadModule alias_module modules/mod_alias.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule proxy_module modules/mod_proxy.so

KeepAlive Off
Listen <PORT_NUMBER>

ServerSignature Off
ServerTokens Prod

StartServers 1
MinSpareServers 1
MaxSpareServers 3
MaxClients 5
MaxRequestsPerChild 100
ServerLimit 4
HostnameLookups Off

NameVirtualHost 127.0.0.1:<PORT_NUMBER>
ServerAdmin <SERVER_ADMIN_EMAIL>

# Run in separate group to avoid timezone issues
# 
http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Timezone_and_Locale_Settings:
WSGIDaemonProcess UTC maximum-requests=100 inactivity-timeout=60
display-name=%{GROUP}
WSGIDaemonProcess AEST maximum-requests=100 inactivity-timeout=60
display-name=%{GROUP}
# (frequent restarts to keep memory down on shared hosting package)

WSGIRestrictEmbedded On
# (http://blog.dscpl.com.au/2009/11/save-on-memory-with-modwsgi-30.html)

<VirtualHost 127.0.0.1:<PORT_NUMBER>>
    WSGIProcessGroup AEST
    WSGIScriptAlias / <HOME>/webapps/django/<PROJECT_A>.wsgi
    ServerName <PROJECT_A_DOMAIN>
</VirtualHost>

<VirtualHost 127.0.0.1:<PORT_NUMBER>>
    WSGIProcessGroup AEST
    WSGIScriptAlias / <HOME>/webapps/django/<PROJECT_B>.wsgi
    ServerName <PROJECT_B_DOMAIN>
</VirtualHost>

# etc. Twenty or so more sites here...


[3] Standard WSGI script:
import os
import sys

# avoid WSGI errors with output to stdout
sys.stdout = sys.stderr

sys.path = [
    '<HOME>/webapps/django', # for PROJECT_NAME
    '<HOME>/.pythonpath', # other packages
    '<HOME>/webapps/django/%s' % PROJECT_NAME, # within project
    ] + sys.path

settings_module_path = '%s.%s' % (PROJECT_NAME, SETTINGS_MODULE_NAME)

os.environ['DJANGO_SETTINGS_MODULE'] = settings_module_path

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to