Brian Brown wrote:
> I'm trying to use sessions, but when the code reaches line 92 
> in Page.py:
> 
> if not self._session:
> 
> then I get the following traceback:
> Traceback (most recent call last):
> File "WebKit/Application.py", line 348, in dispatchRequest
> self.handleGoodURL(transaction)
> File "WebKit/Application.py", line 494, in handleGoodURL
> self.createServletInTransaction(transaction)
> File "WebKit/Application.py", line 901, in createServletInTransaction
> inst = self.getServlet(transaction,path,cache)
> File "WebKit/Application.py", line 828, in getServlet
> inst = factory.servletForTransaction(transaction)
> File "WebKit/ServletFactory.py", line 190, in servletForTransaction
> return theClass()
> File "/home/brian/dist/Python/Webware/WebKit/Dev/index.py", 
> line 27, in 
> __init__
> self.Initialize()
> File "/home/brian/dist/Python/Webware/WebKit/Dev/index.py", 
> line 68, in 
> Initialize
> self._StartJabber()
> File "/home/brian/dist/Python/Webware/WebKit/Dev/index.py", 
> line 108, in 
> _StartJabber
> sess = self.session()
> File "WebKit/Page.py", line 92, in session
> if not self._session:
> AttributeError: index instance has no attribute '_session'
> 
> Any thoughts?

It looks like you're trying to access the session in the __init__ of a
servlet.  But that won't work, for various reasons.  A session is keyed by a
session ID that is sent in a cookie as part of each request from the
browser.  A servlet is instantiated once when it is needed, but will
subsequently service many requests from many different sessions.  Therefore,
you can only access the session object while you're actually processing a
request.  Before that point there wouldn't be any way to tell which session
to use, because sessions are tied to requests.

In practice, it means you should only use self.session() within your servlet
methods like writeContent(), writeHTML(), etc.

Also, you can use self.session() within your servlet's awake() after you've
called the base class's awake(), or within your servlet's sleep() before
you've called the base class's sleep().  (You may or may not actually be
using awake() and sleep() -- it's never necessary to use them but they can
be convenient for some things.)

I hope that made some sense...

-- 

- Geoff Talvola
  [EMAIL PROTECTED]

_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to