Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple django sites on Apache / Windows / mod_wsgi - problem with win32

I have two django sites that use the same database and share some of the code. The main parent site is an extranet for staff and contractors, while the second site exposes some of the data to a few of our partners.

I have managed to set up sites to work but found that if I launched Apache and went into the main site, then the partner site wouldn't work, returning an "Internal Server Error". If I restarted and went into the partner site, then the main site wouldn't work.

So I guess they are conflicting over resources.

The server log (see bottom) shows that it is a problem with the win32/lib/pywintypes.py module, line 114. Elsewhere, it's been suggested to comment out these lines (see below). So I've tried this and it works.

I don't really understand what is going on in the code and whether commenting it out is just going to cause me problems later. So the question is:

Is there something else going on that may be causing this? Is this fudge 'safe' to do?

# py2k and py3k differences:
# On py2k, after doing "imp.load_module('pywintypes')", sys.modules
# is unchanged - ie, sys.modules['pywintypes'] still refers to *this*
# .py module - but the module's __dict__ has *already* need updated
# with the new module's contents.
# However, on py3k, sys.modules *is* changed - sys.modules['pywintypes']
# will be changed to the new module object.
# SO: * on py2k don't need to update any globals.
#     * on py3k we update our module dict with the new module's dict and
#       copy its globals to ours.
old_mod = sys.modules[modname]
# Python can load the module
mod = imp.load_dynamic(modname, found)
# Check the sys.modules[] behaviour we describe above is true...
if sys.version_info < (3,0):
    #The fudge bit !!!!!!!!!!!!!!!!!
    #assert sys.modules[modname] is old_mod 
    #assert mod is old_mod
    pass
else:
    assert sys.modules[modname] is not old_mod
    assert sys.modules[modname] is mod
    # as above - re-reset to the *old* module object then update globs.
    sys.modules[modname] = old_mod
    globs.update(mod.__dict__)

Traceback

    mod_wsgi (pid=7164): Exception occurred processing WSGI script 'E:/Programming/django_site/extranet_site/apache/django.wsgi'.
Traceback (most recent call last):              
File "C:\\Python26\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 241, in __call__
    response = self.get_response(request)
File "C:\\Python26\\lib\\site-packages\\django\\core\\handlers\\base.py", line 73, in get_response              
        response = middleware_method(request)               
ile "C:\\Python26\\lib\\site-packages\\django\\contrib\\sessions\\middleware.py", line 10, in process_request               
        engine = import_module(settings.SESSION_ENGINE)             
File "C:\\Python26\\lib\\site-packages\\django\\utils\\importlib.py", line 35, in import_module             
        __import__(name)                
File "C:\\Python26\\lib\\site-packages\\django\\contrib\\sessions\\backends\\db.py", line 2, in <module>                
    from django.contrib.sessions.models import Session              
File "C:\\Python26\\lib\\site-packages\\django\\contrib\\sessions\\models.py", line 4, in <module>              
    from django.db import models                
File "C:\\Python26\\lib\\site-packages\\django\\db\\models\\__init__.py", line 12, in <module>              
    from django.db.models.fields.files import FileField, ImageField             
File "C:\\Python26\\lib\\site-packages\\django\\db\\models\\fields\\files.py", line 8, in <module>              
        from django.core.files.storage import default_storage               
File "C:\\Python26\\lib\\site-packages\\django\\core\\files\\storage.py", line 7, in <module>               
    from django.core.files import locks, File               
File "C:\\Python26\\lib\\site-packages\\django\\core\\files\\locks.py", line 25, in <module>                
    import pywintypes               
File "C:\\Python26\\lib\\site-packages\\win32\\lib\\pywintypes.py", line 124, in <module>               
    __import_pywin32_system_module__("pywintypes", globals())               
File "C:\\Python26\\lib\\site-packages\\win32\\lib\\pywintypes.py", line 114, in __import_pywin32_system_module__               
    assert sys.modules[modname   is old_mod         
AssertionError              
like image 647
alj Avatar asked May 11 '11 19:05

alj


2 Answers

Installing pywin32 #212 solved the problem.

like image 177
Marek Stój Avatar answered Sep 29 '22 13:09

Marek Stój


It worked for me after removing pywin32 and using WSGIScriptAlias "/aliasname" "c:/wamp/www/project/django.wsgi" In httpd.config Use quotes for the first parameter also.

like image 28
kiran.gilvaz Avatar answered Sep 29 '22 13:09

kiran.gilvaz