mod_python & Cookie - unexpected dictionary value

J

Jan Danielsson

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 ----
 
J

Jan Danielsson

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 ----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top