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 13 2056
Manlio Perillo <NO******************@libero.it> pisze: 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"
You must use date in UTC format.
--
Jarek Zgoda http://jpa.berlios.de/
On Sat, 22 May 2004 20:06:45 +0000 (UTC), Jarek Zgoda
<jz****@gazeta.usun.pl> wrote: Manlio Perillo <NO******************@libero.it> pisze:
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"
You must use date in UTC format.
This is the date format used by the server cookie!
Thanks and Regards Manlio Perillo
Manlio Perillo <NO******************@libero.it> pisze: 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"
You must use date in UTC format.
This is the date format used by the server cookie!
See http://www.w3.org/TR/NOTE-datetime on how should date look in
cookies. If date is not in valid format, the module functions may have
trouble decoding it.
--
Jarek Zgoda http://jpa.berlios.de/
On Sun, 23 May 2004 18:36:52 GMT, JanC <us*********@janc.invalid>
wrote: Manlio Perillo <NO******************@libero.it> schreef:
I'm using the Cookie module (on the client side).
Do you know the ClientCookie module? <http://wwwsearch.sourceforge.net/ClientCookie/>
Yes, I know; but the standard Cookie module is sufficient.
Thanks and regards
On Sun, 23 May 2004 17:12:25 +0000 (UTC), Jarek Zgoda
<jz****@gazeta.usun.pl> wrote: Manlio Perillo <NO******************@libero.it> pisze:
>You must use date in UTC format. This is the date format used by the server cookie! See http://www.w3.org/TR/NOTE-datetime on how should date look in cookies. If date is not in valid format, the module functions may have trouble decoding it. It is not a my problem!
As you see, it's your problem, since it's you who cann't decode this cookie. ;)
The problem is also of Cookie module. The web server follow the Netscape specification for Cookies and in this spec the date is in the format I have posted.
Netscape is not internet God, W3C is.
Unfortunately we don't live in a perfect world... ;)
I never tried to read cookies using Cookie module (I used Python only for writing), so I cann't help more here. Good luck.
Ok, thanks.
Regards Manlio Perillo
Manlio Perillo <NO******************@libero.it> writes:
[...] I'm trying to fix the regular expression patternin Cookie.py but it does not work:
[...]
Yeah, IIRC there's some odd stuff in there, that doesn't even seem to
come from the standards, let alone reality ;-)
The Cookie module really doesn't know how to handle cookies on the
client side. Use this, which does: http://wwwsearch.sf.net/ClientCookie/
You can just say:
ClientCookie.urlopen("http://www.example.com/")
and be done with it.
John
On 27 May 2004 22:52:10 +0100, jj*@pobox.com (John J. Lee) wrote: Manlio Perillo <NO******************@libero.it> writes: [...] I'm trying to fix the regular expression patternin Cookie.py but it does not work:[...]
Yeah, IIRC there's some odd stuff in there, that doesn't even seem to come from the standards, let alone reality ;-)
I have fixed the pattern.
For matching spaces it is needed '\ ' and not ' '.
Here is the code.
Now the Cookie parse the Netscape format.
_LegalCharsPatt = r"[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]"
_WeekPatt = r"(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)"
_MonthPatt = r"(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|D ec)"
_DatePatt = r"(?:" + _WeekPatt + r",\ \d{2}-" + _MonthPatt +\
r"-\d{4}\ \d{2}:\d{2}:\d{2}\ GMT)"
_CookiePattern = re.compile(
r"(?x)" # This is a Verbose pattern
r"(?P<key>" # Start of group 'key'
""+ _LegalCharsPatt +"+?" # Any word of at least one letter,\
nongreedy
r")" # End of group 'key'
r"\s*=\s*" # Equal Sign
r"(?P<val>" # Start of group 'val'
r'"(?:[^\\"]|\\.)*"' # Any doublequoted string
r"|" # or
""+ _DatePatt + "" # A date as specified by Netscape\
spec
r"|" # or
""+ _LegalCharsPatt +"*" # Any word or empty string
r")" # End of group 'val'
r"\s*;?" # Probably ending in a semi-colon
)
I also have added a method to BaseCookie that behaves like
Morsel.OutputString:
def OutputString(self, attrs=None, sep='\n'):
"""Return a string suitable for HTTP.
"""
result = []
items = self.items()
items.sort()
for K,V in items:
result.append( V.OutputString(attrs) )
return sep.join(result)
Now the Cookie is usable on the client side too.
The Cookie module really doesn't know how to handle cookies on the client side.
It does not matter, all the cookie logic for my program is very very
simple and standard Cookie is all I need.
Use this, which does:
http://wwwsearch.sf.net/ClientCookie/
You can just say:
ClientCookie.urlopen("http://www.example.com/")
and be done with it.
I have seen the module, but it is too complicated.
Standard Cookie module (with my corrections) plus httplib module is
really all I need.
Thanks and regards Manlio Perillo
Manlio Perillo <NO******************@libero.it> writes: On 27 May 2004 22:52:10 +0100, jj*@pobox.com (John J. Lee) wrote:
[...]You can just say:
ClientCookie.urlopen("http://www.example.com/")
and be done with it.
I have seen the module, but it is too complicated.
Having written it, I agree, but I don't think it's my fault <wink>.
Standard Cookie module (with my corrections) plus httplib module is really all I need.
Cool.
John
On 29 May 2004 12:26:59 +0100, jj*@pobox.com (John J. Lee) wrote: Manlio Perillo <NO******************@libero.it> writes:
On 27 May 2004 22:52:10 +0100, jj*@pobox.com (John J. Lee) wrote:[...] >You can just say: > >ClientCookie.urlopen("http://www.example.com/") > >and be done with it. >
I have seen the module, but it is too complicated.
Having written it, I agree, but I don't think it's my fault <wink>.
Well, it is too complicated for me. 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.
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(newcookie)
- ...
- save the cookie to a file
This is very simple to do with httplib and Cookie modules, so why to
use more involved modules?
Regards Manlio Perillo
Manlio Perillo <NO******************@libero.it> 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(newcookie) - ... - 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
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(newcookie) - ... - 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
Manlio Perillo <NO******************@libero.it> 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
On 01 Jun 2004 20:28:03 +0100, jj*@pobox.com (John J. Lee) wrote: Manlio Perillo <NO******************@libero.it> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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).
...
|
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...
|
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...
|
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,
...
|
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...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |