mod_python & Cookie - unexpected dictionary value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan Danielsson

    #1

    mod_python & Cookie - unexpected dictionary value

    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_cook ies(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_heade r() 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=bla h". The cookie is
    set using:

    c = Cookie.Cookie(' sessId', 'blah')
    c.expires = time.time() + 60*30
    Cookie.add_cook ie(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_cook ies(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 ----
  • Jan Danielsson

    #2
    Re: mod_python & Cookie - unexpected dictionary value

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

    Comment

    Working...