Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > mod_python & Cookie - unexpected dictionary value

Reply
Thread Tools

mod_python & Cookie - unexpected dictionary value

 
 
Jan Danielsson
Guest
Posts: n/a
 
      04-13-2007
Hello all,

I'm sure I'm not using this right, but I don't understand what I'm
doing wrong. What I want is to get all the cookies from the request,
then extract the 'sessId' cookie. I'm using this code:

-----------------
from mod_python import Cookie

[---]

def index(req, sessId = None):

cookies = Cookie.get_cookies(req)

if not sessId and cookies.has_key('sessId'):
sessId = cookies['sessId']

sess = Session(req, sessId)

httphdr(req)
-----------------

(Note: The Session() constructor will attempt to set the cookie, and
httphdr() is responsible for the send_http_header() call).

This is the part I don't understand. If the sessId cookie exists, it
will fail because the returned sessId object will be a Cookie object. If
I print str(sessId), I will get the output "sessId=blah". The cookie is
set using:

c = Cookie.Cookie('sessId', 'blah')
c.expires = time.time() + 60*30
Cookie.add_cookie(req, c)

So, the part I don't understand is why

sessId = cookies['sessId']

... is returning a Cookie-object. I would have expected to get a
string containing "blah"?

I can get this to work, by doing this:


cookies = Cookie.get_cookies(req)
c = str(cookies['sessId']).split('=', 1)

...then use c[1]. Is that the proper way? Seems kind of strange to
store the cookies in a dictonary without being able to use the benefits
of them?


--
Kind regards,
Jan Danielsson
------------ And now a word from our sponsor ------------------
Want to have instant messaging, and chat rooms, and discussion
groups for your local users or business, you need dbabble!
-- See http://netwinsite.com/sponsor/sponsor_dbabble.htm ----
 
Reply With Quote
 
 
 
 
Jan Danielsson
Guest
Posts: n/a
 
      04-13-2007
Jan Danielsson wrote:
[---]

Never mind. Cookie objects have a "value" attribute -- that's what I
was doing wrong.

--
Kind regards,
Jan Danielsson
------------ And now a word from our sponsor ------------------
Want to have instant messaging, and chat rooms, and discussion
groups for your local users or business, you need dbabble!
-- See http://netwinsite.com/sponsor/sponsor_dbabble.htm ----
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP : how can directly get the value of a specified cookie namewithout using a loop FROM the header.cookie ? stunaz Java 2 12-24-2010 03:08 PM
Unexpected behavior with dictionary keys containment and auser-defined class Rob Clewley Python 3 01-13-2009 04:13 AM
Re: Sort dictionary by value when value is a list Chris Rebert Python 0 11-14-2008 08:10 PM
mod_python.so is garbled mod_python.so is garbled blbmdsmith Python 1 12-14-2006 12:15 AM
[DICTIONARY] - Copy dictionary entries to attributes Ilias Lazaridis Python 6 02-21-2006 11:27 AM



Advertisments