[urllib2] 302 -> can't get cookie

Gilles Ganault nospam at nospam.com
Wed Jan 7 12:27:00 CET 2009


I'm using urllib2 to connect to a web server with POST, and then the
server sends a cookie to hold the session ID, but also redirects the
user to another page:

HTTP/1.1 302 Found
Date: Wed, 07 Jan 2009 11:20:51 GMT
Server: Apache
Set-Cookie: PHPSESSID=4015f14eb04dc81159253a9533a7c590; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
Pragma: no-cache
Location: second_page.php
Content-Length: 0
Connection: close
Content-Type: text/html; charset=ISO-8859-1

As a result, urllib2 follows this new page, and the HTTP header that I
get is the one from the second page.

Is there a way to ignore this second page, and stick to the first page
through which I connect?

Thank you.

More information about the Python-list mailing list