[Zope] session and iterating session_data

Bakhtiar A Hamid kedai@kedai.com.my
Fri, 4 Oct 2002 14:44:32 +0800


hi
in an attempt to provide users with list of those online, i'm using sessi=
on to=20
keep track of who's logged in , and who's timed out (inactivity)

in essence,=20
-when users log in, i start a session, and store their username in the se=
ssion=20
object

-i then have an external method that goes thru session data in temp_folde=
r=20
(where session objects are stored) and iterate thru the session objects, =
and=20
return the usernames[1]

this scheme works, but some, maybe many, times, i encountered Key Error[2=
, and=20
many times it's the same key error].

is there anything wrong with my way of approcahing this?  or is there a b=
etter=20
way?

zope2.5.1/zope2.6.0b1, python2.1.3, linux

help appreciated.

tia
--
[1]
def getsession_data(self):

        import time
        l =3D []
        for session in self.temp_folder.session_data.values():
                username =3D session.get('username','Unknown')
                last_xs =3D time.ctime(session.getLastAccessed())
                l.append((username,last_xs))
        return l

[2]


Error type:  KeyError
Traceback: <p>Traceback (innermost last):
<ul>
<li>  Module ZPublisher.Publish, line 98, in publish</li>
<li>  Module ZPublisher.mapply, line 88, in mapply</li>
<li>  Module ZPublisher.Publish, line 39, in call_object</li>
<li>  Module OFS.DTMLMethod, line 126, in __call__</li>
<li>  Module DocumentTemplate.DT_String, line 474, in __call__</li>
<li>  Module DocumentTemplate.DT_Util, line 201, in eval<br />
__traceback_info__: sc_gSessionData</li>
<li>  Module &lt;string&gt;, line 2, in f</li>
<li>  Module Shared.DC.Scripts.Bindings, line 252, in __call__</li>
<li>  Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec</li>
<li>  Module Products.PythonScripts.PythonScript, line 315, in _exec</li>
<li>  Module Script (Python), line 1, in sc_gSessionData<br />
<b>&lt;PythonScript at /kk/sc_gSessionData&gt;</b><br />
<b>Line 1</b></li>
<li>  Module Products.ExternalMethod.ExternalMethod, line 231, in __call_=
_<br=20
/>
__traceback_info__: ((), {}, None)</li>
<li>  Module /home/xxx/ZopeHome/Extensions/session.py, line 30, in=20
getsession_data</li>
<li>  Module Products.Transience.Transience, line 832, in values</li>
<li>  Module Products.Transience.Transience, line 832, in &lt;lambda&gt;<=
/li>
<li>  Module Products.Transience.Transience, line 755, in __getitem__</li=
>
</ul>KeyError: 1033629200
</p>

--=20

=09http://www.kedai.com.my/             http://www.kedai.com.my/eZine
=09http://www.zope.org/Members/kedai    http://www.my-zope.org
=09I will follow you! Damage Inc.