Cannot redirect to a SessionWrapper-wrapped page (example code included)
Hi all. I've got the following setup on a nevow site (actually, it's an Athena site, but I suspect that's incidental): - I want the initial visit to the root to be redirected to a named location on the same site (that is, http://foo.com/ => http://foo.com/bar); - I want the named location to present a login page using guard.SessionWrapper and twisted.cred; - Once authenticated, the application proper is available at the name location. At the moment, I've got the following situtation: - Publishing the DummyPage() at the root works. - Publishing the LivePage() without the SessionWrapper at the root works[1]. - Publishing the LivePage with the SessionWrapper at the root works. - Redirecting to the DummyPage() works. - Redirecting to the LivePage without the SessionWrapper works. - However, redirecting to the LivePage with the SessionWrapper seems to get into some sort of loop. [1] Where "publishing at the root" means, "passing the resource to appserver.NevowSite()" on line 157-ish The cred and guard stuff is more or less lifted from nevow/examples/guarded.py Specifically, Firefox 2.0.0.3 (at least, that's what it reports; it's the latest version on Ubuntu Feisty) says: """ The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. * This problem can sometimes be caused by disabling or refusing to accept cookies. """ (It is set up to accept all cookies). Internet Explorer 6 (ies4linux) simply says that the site is unavailable, but I can see from the server side logs that it is hitting the server multiple times, in the same way as FF. The server prints out something like this (I'm editing, because it's quite verbose): "GET / HTTP/1.1" "GET /foopage HTTP/1.1" "GET /foopage/__session_key__ae8692cb175716b50ba92a316f586f97 HTTP/1.1" "GET /foopage?__start_session__=1 HTTP/1.1" "GET /foopage/__session_key__9237e1a6dcd263df40dc3f6357167474?__start_session__=1 HTTP/1.1" "GET /foopage?__start_session__=1 HTTP/1.1" "GET /foopage/__session_key__6e06ee432ba04231e1b1e887d024f04c?__start_session__=1 HTTP/1.1" ... [repeated about 10 times in total] ... [delay] expired session ae8692cb175716b50ba92a316f586f97 expired session 9237e1a6dcd263df40dc3f6357167474 [repeated about 10 times in total] I've attached a single-file example of the problem. Can anyone spot what I'm doing wrong? Regards, Ricky
On 10:51 am, iacovou@gmail.com wrote:
Specifically, Firefox 2.0.0.3 (at least, that's what it reports; it's the latest version on Ubuntu Feisty) says:
""" The page isn't redirecting properly
The guard wrapper is being re-created on every hit in the child_foopage method. So, the session storage is getting re-created on every hit, which means that your session isn't being stored anywhere that the resource can access it. So each time the browser hits it, it tries to recreate its session. Put the guard wrapper somewhere persistent so that it will be the *same* guard wrapper accessed on subsequent hits, and it will work.
On Monday 16 July 2007 17:11:25 glyph@divmod.com wrote:
The guard wrapper is being re-created on every hit in the child_foopage method. So, the session storage is getting re-created on every hit, which means that your session isn't being stored anywhere that the resource can access it. So each time the browser hits it, it tries to recreate its session.
Put the guard wrapper somewhere persistent so that it will be the *same* guard wrapper accessed on subsequent hits, and it will work.
Yes, that's it; thanks Glyph. Actually, while we're on the subject, there's one more oddity. It's not terribly important for reasons I'll describe below, but it's still something that confuses me. If I patch the file in my previous attachment to create and reuse a single persistent guard wrapper, like this: class TopLevel ( rend.Page ): def __init__ ( self ): rend.Page.__init__ ( self ) self.gresource = createGuardedResource() [...] def child_foopage ( self, ctx ): return self.gresource ... then the looping disappears BUT I get the "cannot render livepage more than once" error. The way to overcome this seems to be to uncomment the "child_()" method in FooPage(): def child_ ( self, ctx ): return FooPage() ... so that any attempt to access the path of the LivePage afresh will get a new instance of the page. I want this behaviour anyway, because I don't want browser refreshes to throw up an error. However, I'm confused as to why this error would occur the FIRST time I access the LivePage after GuardWrapper authentication. As far as I can tell, I've just rendered the page once. Regards, Ricky
participants (2)
-
glyph@divmod.com -
kgi