Sending cookies with python. When download with python

Yongjian Xu jimxu at
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():
   return req

Hope it helps.

On 6/5/07, moishyyehuda at <moishyyehuda at> 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.
> --

Yongjian (Jim) Xu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list