Getting a cookie
Calvelo Daniel
dcalvelo at pharion.univ-lille2.fr
Wed Oct 4 10:38:07 EDT 2000
Jose Isaias Cabrera <jicman at cinops.xerox.com> wrote:
[snip context]
: print hdrs
:
: and I get
:
: Date: Mon, 02 Oct 2000 16:21:07 GMT
: Server: Apache/1.3.0 (Unix)
: Set-Cookie: Blah-blah=78s82%23^%%%^
: Connection: close
: Content-Type: text/xml
Which is *one* string.
: but I can not get the content of the cookie into a variable because I can't
: not search through it or anything. If I use the line,
:
: for x in hdrs:
: print x
:
: it gives me the error
[snip]
If you want to parse the 'hdrs' string to obtain the 'Set-Cookie' fields,
try something like:
>>> hdrs = """Date: Mon, 02 Oct 2000 16:21:07 GMT
... Server: Apache/1.3.0 (Unix)
... Set-Cookie: Blah-blah=78s82%23^%%%^
... Connection: close
... Content-Type: text/xml"""
>>> for each_line in string.split( hdrs,'\n' ):
... field, content = string.split( each_line, ': ')
... if field=='Set-Cookie': print content
...
Blah-blah=78s82%23^%%%^
The standard module 'mimetools' might be useful to you too.
HTH, DCA
-- Daniel Calvelo Aros
calvelo at lifl.fr
More information about the Python-list
mailing list