Sending cookies with python. When download with python

Yongjian Xu jimxu at google.com
Tue Jun 5 19:38:16 CEST 2007


yes. urllib2 has Request class that compose html headers (dict object) into
a request object where you can put Cookie: header into it. Also, there are a
few Cookie related modules you can use too.

An example using urllib2 can be something like this:

def myrequest(url):
   req = urllib2.Request(url)
   headers = {'Cookie':'cookies','some_other_headers':'contents'}
   for k,v in headers.iteritems():
      req.add_header(k,v)
   return req

Hope it helps.
Jim

On 6/5/07, moishyyehuda at gmail.com <moishyyehuda at gmail.com> wrote:
>
> I need to download files off a password protected website. So if I try
> to download files off the site with python I will be blocked. Is there
> anyway to send cookies with python. So I will be authenticated.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Yongjian (Jim) Xu
===========
Sysops
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070605/5ea0f5d3/attachment.html>


More information about the Python-list mailing list