Reetesh,
I also looked over your urllib2 example. It seems like it should work.
When I have to deal with a login which handles the session through a cookie, I will just install the opener globally to make it easier to deal with. After I run urllib2.install_opener(opener), I can simply call urllib2.urlopen() without worrying about setting up the cookies or interfacing with the opener that was built.
For us, it would be helpful to know why you are inspecting cookies? What's the end goal? There may well be a different solution than dealing with the specific cookie problem.
For you, it might be helpful to understand exactly what cookies are (
http://en.wikipedia.org/wiki/HTTP_cookie). To paraphrase, the server will send a cookie key/value pair back to the client. From then on the client is expected to send that cookie back to the server as part of each request. This is exactly why the opener is necessary. It will handle the persistent client information.
I just dug up a recent script that I am using urllib2 with. It's a one-off script that I hashed out without much care, but I think it's legible.
For those that don't want to read the source, it's a downloader for VRay nightlies. My studio has been doing some serious testing of the GPU rendering, and we always want the latest build available.
Cheers,
jesse