[Tutor] retrieving httponly cookies on accessing webpage with urllib2

Kent Johnson kent37 at tds.net
Sat Oct 18 19:32:23 CEST 2008

On Sat, Oct 18, 2008 at 12:26 PM, xbmuncher <xboxmuncher at gmail.com> wrote:
> Apparently, the right
> page was a redirection of the original page. When I used to use cURL in PHP
> I remember that it had an option to automatically follow redirects. How can
> I do this with urllib2?

urllib2 will follow HTTP redirects (30x status codes). It won't follow
redirects in <meta> tags or JavaScript. The fetch_html() function here
will follow some <meta> redirects:

> For the headers, I did verify that it sent the headers as I had formed them
> (just not in the right order) with wireshark. So my method does work, I also
> got this method from here:
> http://www.voidspace.org.uk/python/articles/urllib2.shtml#headers

OK. I have definitely had trouble with that in the past but maybe it
is fixed now.


More information about the Tutor mailing list