title: Retrieving only HTTP header without the content in Python
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/107405/how-do-you-send-a-head-http-request-in-python">How do you send a HEAD HTTP request in Python?</a>  </p>
  </blockquote>
  
  
  
  <p>I am using Python's urllib and urllib2 to do an automated login. I am also using HTTPCookieProcessor to automate the handling of the cookies. The code is somewhat like this:</p>
  
  <pre><code>o = urllib2.build_opener( urllib2.HTTPCookieProcessor() )
  # assuming the site expects 'user' and 'pass' as query params
  p = urllib.urlencode( { 'username': 'me', 'password': 'mypass' } )
  # perform login with params
  f = o.open( 'http://www.mysite.com/login/',  p )
  data = f.read()
  f.close()
  # second request
  t = o.open( 'http://www.mysite.com/protected/area/' )
  data = t.read()
  t.close()
  </code></pre>
  
  <p>Now, the point is that I don't want to waste bandwidth in downloading the contents of <a href="http://www.mysite.com/login/" rel="nofollow noreferrer">http://www.mysite.com/login/</a>, since all I want to do is receive the cookies (which are there in the Headers). Also, the site redirects me to <a href="http://www.mysite.com/userprofile" rel="nofollow noreferrer">http://www.mysite.com/userprofile</a> when I first login (that is, the f.geturl() =  <a href="http://www.mysite.com/userprofile" rel="nofollow noreferrer">http://www.mysite.com/userprofile</a>).</p>
  
  <p>So is there any way that I can avoid fetching the content in the first request?</p>
  
  <p>P.S. Please don't ask me why am I avoiding the small network usage of transferring the content. Although the content is small, I still don't want to download it.</p>