[Zope] session and iterating session_data

Chris McDonough chrism@zope.com
04 Oct 2002 08:05:00 -0400


This is likely to happen under 2.5.1 but not 2.6b1.  Are you sure you
get the key error under 2.6b1?

On Fri, 2002-10-04 at 02:44, Bakhtiar A Hamid wrote:
> hi
> in an attempt to provide users with list of those online, i'm using session to 
> keep track of who's logged in , and who's timed out (inactivity)
> 
> in essence, 
> -when users log in, i start a session, and store their username in the session 
> object
> 
> -i then have an external method that goes thru session data in temp_folder 
> (where session objects are stored) and iterate thru the session objects, and 
> return the usernames[1]
> 
> this scheme works, but some, maybe many, times, i encountered Key Error[2, and 
> many times it's the same key error].
> 
> is there anything wrong with my way of approcahing this?  or is there a better 
> way?
> 
> zope2.5.1/zope2.6.0b1, python2.1.3, linux
> 
> help appreciated.
> 
> tia
> --
> [1]
> def getsession_data(self):
> 
>         import time
>         l = []
>         for session in self.temp_folder.session_data.values():
>                 username = session.get('username','Unknown')
>                 last_xs = 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 
> />
> __traceback_info__: ((), {}, None)</li>
> <li>  Module /home/xxx/ZopeHome/Extensions/session.py, line 30, in 
> 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>
> 
> -- 
> 
> 	http://www.kedai.com.my/             http://www.kedai.com.my/eZine
> 	http://www.zope.org/Members/kedai    http://www.my-zope.org
> 	I will follow you! Damage Inc.
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )