Getting a cookie

Jose Isaias Cabrera jicman at cinops.xerox.com
Wed Oct 4 10:20:15 EDT 2000


Hi all!

Using

import httplib

I did a POST to a server to login to it with the following http connection:

h = httplib.HTTP(host,port)

I used the code

reply, msg, hdrs = h.getreply()

to get the reply, the message and the headers (duh!).  In the headers (hdrs), I have a cookie returned with a header "Set-Cookie".  I could print the header (hdrs) to STDOUT, by using

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

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

Traceback (innermost last):
  File "C:\MYPROG~1\MyHTTP.py", line 93, in ?
    Cookie = gologin(loginID,password)
  File "C:\MYPROG~1\MyHTTP.py", line 70, in gologin
    for x in hdrs:
  File "d:\Program Files\Python\Lib\rfc822.py", line 356, in __getitem__
    return self.dict[string.lower(name)]
TypeError: read-only character buffer, int

 
So, the question is, how can I get the cookie into a variable that I can use to sent to that server?  Or how can I read this information given back by the server in some kind of bin-hex mode?

thanks for your help,

jose


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20001004/8ed63063/attachment.html>


More information about the Python-list mailing list