[mod_python] Cookies and sessions trouble

Wouter van Marle wouter at squirrel-systems.com
Thu May 12 23:39:03 EDT 2005


On Thu, 2005-05-12 at 23:24 -0400, Graham Dumpleton wrote:
> Wouter van Marle wrote ..
> > Sometimes I feel so stupid... remembering "no req.write before finishing
> > the cookies", Stripping those, the cookies part at least works within
> > this test module, and seems to work OK in the real page as well. Now the
> > rest of the problems still persist:
> > 
> > main.py/home produces a page that a.o. links to user.py/register.
> > 
> > user.py imports main.py (import main), and sometimes gets the error
> > message "No module named main". Sometimes it goes fine, and the module
> > is imported and starts running.
> > 
> > It seems the include goes well, as long as I to it within a minute or
> > two from loading the home page (main.py/home). If quickly after that I
> > click <reload> in the browser it goes fine, a moment later I get the
> > include error.
> > 
> > Also I just noticed that changes made to main.py are not used when
> > including main in user.py, until I restart apache. I got some old
> > wordings that were changed in the source. Some too persistent caching at
> > work here?
> 
> 
> Using "import main" is not a good idea when the "main.py" is also being
> loaded by mod_python by its module loading system. Instead of:
> 
>   import main
> 
> use:
> 
>   main = apache.import_module("main")
> 

Graham, 

apache.import_module("main") works, as in it loads the module, however
now the "module not found" errors have been replaced by "AttributeError:
'module' object has no attribute 'get_session'" errors. So still not
really a solution...

I'll at least check out the apache module, maybe indeed something
different to what you suggested.

Wouter.


> You may have to use something like:
> 
>   import os
> 
>   directory = os.path.split(__file__)[0]
>   main = apache.import_module("main",path=[directory])
> 
> if wanting to load a module from a location not in sys.path. The latter is
> in some ways perfered so as to make sure you get the correct version.
> 
> Hmmm, this all may not work in mod_python 3.2 from what I have
> seen of changes to module loading mechanism used specifically for
> mod_python.publisher in that version. You may have to replace use of
> apache.import_module() with use of publisher specific module loader
> in that version when it is available.
> 
> Graham
> 
> 



More information about the Mod_python mailing list