[mod_python] Sessions in 2.7 [solved]

Gonzalo Sainz-Trápaga gomo at datafull.com
Tue Jul 12 21:17:30 EDT 2005


Hi,

On Mon, 2005-07-11 at 21:41 -0300, Gonzalo Sainz-Trápaga wrote:
> Hi, I just realized mod_python 3.x is only available for Apache 2.0.
> Sadly, I realized it by reading:
> ImportError: No module named Session
> In my browser after having uploaded everything.
> 
> So I have quite a problem here. I have to find a (sort of) drop-in
> replacement for 3.x sessions, and i have to do it *fast*. I checked the
> links in the FAQ, and the only one that looks like it could work is PSO.

Ok, here's how I worked this out (for the record).
First, I googled quite a bit and finally bumped into Myghty, a Python
port of HTML::Mason. Myghty has it's own Session implementation which is
100% syntax compatible with mod_python's. So, I changed my import
statement and everything ran fine in Apache 2.0 (my local server).

Strangely, the remote server (Apache 1.3) didn't allow me to log in. It
turned out it wasn't sending any cookies. After a *lot* of head smashing
I finally realized (with help from Myghty's author) that mod_python 2.7
requires you to explicitely request.send_http_header() on your handlers,
while 3.1 does not. This is not really mentioned in the documentation,
it is just silently removed from the corresponding page in 3.1's docs.
Adding this single line made everything work fine.

So, what did we learn?
-> When in need for compatibility with Apache 1.3 and 2.0, use Myghty's
sessions instead of mod_python's ones, and use
request.send_http_header() in your handlers to avoid strange, seemingly
unexplainable behaviours.

I also modified the mod_python FAQ and added these 2 things.

Thanks to Graham for the quick reply,

-- 
Gonzalo Sainz-Trápaga (GomoX)
GnuPG Fingerprint: A0AF 3BBF EB93 7EFE 6628  C5A5 F073 9442 6DE4 A497
Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x6DE4A497
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20050712/dc589ece/attachment.bin


More information about the Mod_python mailing list