473,799 Members | 3,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems with module Cookie

Hi.
I'm using the Cookie module (on the client side).
I have found a problem trying to parse the cookie:

"Set-Cookie: value=thevalue; path=/;
expires=Fri, 21-May-2004 10:40:51 GMT"

The date is not parsed correctly, only "Fri," is matched.
Thanks and regards Manlio Perillo
Jul 18 '05
13 2123
Manlio Perillo <NO************ ******@libero.i t> writes:
[...]
Standard Cookie module (with my corrections) plus httplib module is
really all I need.
Cool.


Yes, there exists programs that are simple (as there exist programming
languages that are simple)!

Actually what I do is to download several files from a server.
Some files/pages are generated by a script (so I have to post an
x-www-form-urlencoded string).

I don't want to use urllib2 because it (as I think) for every request
connects to the server, do the request and disconnect.


Yes, that's true. I should fix it...

I need cookies because the server (as many other) authenticate user
with cookies.
So the simple algorithm is:

-connect to the server
-read a cookie from a file
-send the cookie to the server
-if the server send a cookie, the old one must be updated: with
standard Cookie this is simple: cookie.update(n ewcookie)
- ...
- save the cookie to a file
This is very simple to do with httplib and Cookie modules, so why to
use more involved modules?


No reason at all if you're happy with it, of course. That was what my
"Cool" was meant to communicate.

*Using* urllib2 is less involved even than your little algorithm
above, of course (neglecting bugs, of course, including the persistent
connection bug, which -- though it could certainly be a problem -- I
confess has never actually troubled me, despite having used it to
repeatedly fetch tens of millions of records in the past).

Why use modules whose *implementation * is more involved? Because
they're even easier to use, and because, even for simple scripts like
your's, not every case is as simple as the one you happen to have met.
I know from experience that it can quickly get *very* tiresome to do
some of this stuff by hand (even if only a few things like
redirections and cookies are involved). And personally, I don't even
like to *think* about it, or to have to maintain it in future if I can
avoid it, regardless of how simple (ignoring for the moment that I
have to maintain the library itself ;-).

As for why the complications.. . well, if you want to know, read the
code (no, don't :-).
John
Jul 18 '05 #11
On 31 May 2004 01:56:10 +0100, jj*@pobox.com (John J. Lee) wrote:
I need cookies because the server (as many other) authenticate user
with cookies.
So the simple algorithm is:

-connect to the server
-read a cookie from a file
-send the cookie to the server
-if the server send a cookie, the old one must be updated: with
standard Cookie this is simple: cookie.update(n ewcookie)
- ...
- save the cookie to a file
This is very simple to do with httplib and Cookie modules, so why to
use more involved modules?
No reason at all if you're happy with it, of course. That was what my
"Cool" was meant to communicate.

*Using* urllib2 is less involved even than your little algorithm
above, of course (neglecting bugs, of course, including the persistent
connection bug, which -- though it could certainly be a problem -- I
confess has never actually troubled me, despite having used it to
repeatedly fetch tens of millions of records in the past).

Why use modules whose *implementation * is more involved? Because
they're even easier to use, and because, even for simple scripts like
your's, not every case is as simple as the one you happen to have met.


You are right, but: what means 'easier to use'?
There is less code to write?
There is less theory to learn?

For my script using urllib2 does not make the program easier.
I know from experience that it can quickly get *very* tiresome to do
some of this stuff by hand (even if only a few things like
redirections and cookies are involved).


In my case cookie are very easy to use and I simply ignore
redirection...

Of course I agree with you for all other cases, but there exist
programs that really needs only low level library.

Actually, ad example, standard Cookie module is low level.
It only parses key=value pairs, and, more important, it is 'other
library' neutral.
That is, BaseCookie class has a parse method for parsing a string
(as SetCookie: key=value; ....), and an OutputString (added by me)
that returns the cookie data.

Thanks and regards Manlio Perillo

Jul 18 '05 #12
Manlio Perillo <NO************ ******@libero.i t> writes:
On 31 May 2004 01:56:10 +0100, jj*@pobox.com (John J. Lee) wrote: [...]
This is very simple to do with httplib and Cookie modules, so why to
use more involved modules?


No reason at all if you're happy with it, of course. That was what my
"Cool" was meant to communicate.

[...] Of course I agree with you for all other cases, but there exist
programs that really needs only low level library.
Was that not what I said? Sorry if I'm not making myself clear!
(What follows is unrelated to your (quite unnecesary!) extended
defence of your use of Cookie in your script, but just by the way of
commentary on the points you make)
Actually, ad example, standard Cookie module is low level.
Yes. The low-level stuff it does is not not always the right thing
for client-side code, though.

It only parses key=value pairs, and, more important, it is 'other
library' neutral.

[...]

Same goes for ClientCookie. The interface required of request and
response objects is defined in the docs. For doing what ClientCookie
does (automatic cookie handling), I don't think it can get much
simpler.
John
Jul 18 '05 #13
On 01 Jun 2004 20:28:03 +0100, jj*@pobox.com (John J. Lee) wrote:
Manlio Perillo <NO************ ******@libero.i t> writes:
On 31 May 2004 01:56:10 +0100, jj*@pobox.com (John J. Lee) wrote:[...]
>> This is very simple to do with httplib and Cookie modules, so why to
>> use more involved modules?
>
>No reason at all if you're happy with it, of course. That was what my
>"Cool" was meant to communicate.

[...]
Of course I agree with you for all other cases, but there exist
programs that really needs only low level library.


Was that not what I said? Sorry if I'm not making myself clear!


I'm sorry but I not a very expert in english language...

(What follows is unrelated to your (quite unnecesary!) extended
defence of your use of Cookie in your script, but just by the way of
commentary on the points you make)
Actually, ad example, standard Cookie module is low level.
Yes. The low-level stuff it does is not not always the right thing
for client-side code, though.


Why?
It only parses key=value pairs, and, more important, it is 'other
library' neutral.[...]

Same goes for ClientCookie. The interface required of request and
response objects is defined in the docs.


Ok, but I don't want to write additional code for implementing request
and response interface...
For doing what ClientCookie
does (automatic cookie handling), I don't think it can get much
simpler.


Ok. But my program is already very simple using Cookie.

Thanks and regards Manlio Perillo

Jul 18 '05 #14

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

Similar topics

7
4323
by: N.K | last post by:
Hi , Python's existing cookie module doesnt supports new cookie headers SetCookie2 , How to submit a patch for that ? I tried emailing person who owns that module.But no response. Thanks, Nirmal
2
2141
by: sh | last post by:
Hi guys, Well, I have a (maybe dumb) question. I want to write my own little blog using Python (as a fairly small but doable project for myself to learn more deaply Python in a web context). I don't want so far to use a database as a backend, I'd prefer use XML which is enough for a small amount of data the blog would have to deal with.
0
2331
by: | last post by:
I''m having a problem with cookies that is driving me insane :). - If a user comes to http://domain.com and a cookie is set for them, then the user for whatever reason jumps to http://www.domain.com one of the 2 happens: 1) The cookie we set can not be read (expected), but then a new one can not be written ether (I looked at the server headers and although the cookie information is sent, IE ignores it). 2) The cookie from...
2
386
by: Mike | last post by:
1. For some reason after the session has ended and the authentication cookie has expired I'm not being redirected to the login page. Insted I'm be assigned a new authentication cookie? Anyone have any ideas as to what may be causing this? (I'm using Microsoft's example 2. I'm also transferring a forms authentication cookie recieved from a web service (SQL Reporting Services) thru my app to the client. For some reason the expired cookie is...
6
2455
by: thomson | last post by:
Hi All, i do hae a solution in which i do have mulitple projects including Web Projects,, Depending on the functionality it gets redirected to different web projects and it is working fine, for eg: http:DomainName/MainProject/index.aspx, If i login, it gets redirectes to a different Web Project inside the solution like http://DomainName/MainProject/ChildProject/MyPage.aspx..
6
3875
by: Larry Rebich | last post by:
How do I read and write a cookie in an ASP.Net module? I can get this code to work in an aspx.vb class but not in a regular VB module: Response.Cookies.Add(c) Response is not a recognized command in the module. I've tried importing System.Web into the module but that is not allowed.
14
2093
by: ccdetail | last post by:
http://www.tiobe.com/index.htm?tiobe_index Python is the 7th most commonly used language, up from 8th. The only one gaining ground besides VB in the top 10. We're glad, our app is written in python. It's free at http://pnk.com and it is a web timesheet for project accounting
20
6022
by: Aek | last post by:
We recently moved our large codebase over from VS7 to 8 and found that we now get access violations in atexit calls at shutdown when debugging the application in VS2005. This occurs in static members / singletons (especially meyer type singletons) which use locally declared static variables. These variables are normally cleaned up automatically at shutdown of the application by registering with the atexit. I break point the destructor on...
4
1270
by: rodmc | last post by:
Hi, I am trying to set a cookie on a client computer using the Cookie module however all I get is the text being printed in the browser window. Can anyone point me in the right direction so that the cookie data is set without it appearing in the browser? A shortened version of the code is below, in the full version there is also userID check, this seems to work ok. I have removed that portion for the time being as its the writing part that...
0
9687
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
9541
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
10252
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
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
9073
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...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
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
3759
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.