473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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_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 ----
Apr 13 '07 #1
1 2053
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 ----
Apr 13 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rolfe | last post by:
Has anyone had success getting mod_python to run on Apache on Win2K? I'm writing up instructions on how to do this and need your help. When completed, the instructions at the mod_python website and...
0
by: Anthony Raj | last post by:
There's a problem which I'm trying to solve as elegently as possible. Its basically a setup that runs mod_python on Apache and its for a client that needs to generate dynamic reports by pulling...
4
by: Shannon Jacobs | last post by:
I'm doing some trivial surveys, and I want to know if the same user answers twice. Can't really know that, but at least I thought I could check for the same browser/computer combination by using a...
6
by: Jason Collins | last post by:
There seems to be an inconsistency (bug?) in the way the Set-Cookie header is handled by the WebHeaderCollection. That is, the values of Set-Cookie, when an Expires is specified, contain the ","...
2
by: exhuma.twn | last post by:
Hi again, as soon as I try to make use of the "session" object inside a psp-template file, I get the following error: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most...
1
by: Tama | last post by:
Hello, I've didn't find any answer to my problem so I start a new topic. I have installed Apache 1.3.33 on Windows XP. I've also downloaded and installed ActivePython form...
3
by: aking | last post by:
Dear Python people, im a newbie to python and here...so hello! Im trying to iterate through values in a dictionary so i can find the closest value and then extract the key for that...
10
by: DoomedLung | last post by:
Hey, I recently bought "The Javascript and DHTML Cookbook" by Danny Goodman. I'm at Chapter 1, part 1.9 "Reading and Writing Strings for Cookies" and was just interested in a utility function...
5
by: m.banaouas | last post by:
Hi, bonjour, witch versions are suitable to use for apache & mod_python ? Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent versions) without facing any known major...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.