473,779 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ----
Apr 13 '07 #1
1 2069
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
2025
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 on comp.lang.python crediting all those who contributed. <p> Here's what I've done so far - and where I get stuck: <p> 1. I made default installations of the latest versions: - apache_2.0.47-win32-x86-no_ssl.msi - mod_python-3.0.3.win32.exe
0
1278
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 out records from Postgres. Now once the report is generated , we mail the report in csv format to the requested mailid. We're trying to seperate the report generation / mailing part from the
4
5296
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 cookie. Here is the code I have now. In the header, I have the following: <SCRIPT language="JavaScript"> var cookieStatus; if (document.cookie.length > 0) { cookieStatus = 'Cookie exists with value ' + document.cookie; } else {
6
7081
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 "," character. This seems to be incorrectly parsed during GetValues(). A simple example shows it best (there are 2 .aspx pages and an output): AddHeaders.aspx: <%@ Page language="c#" %>
2
3312
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 recent call last): File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
1
3331
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 http://www.activestate.com/. Then I went to http://www.modpython.org/ and search how to use python script with my web pages. I've tried all the version of mod_python under 2.7.11. As I'm under Windows XP, I can only install
3
2926
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 value....what ive done so far: def pcloop(dictionary, exvalue): z = dictionary.itervalues() y = z - exvalue
10
453
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 that grabs a cookie value: function getCookieVal(offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) {
5
3118
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 issue ? thanks for any help.
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9930
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.