title: how to check if the urllib2 follow a redirect?
body: <p>I've write this function:</p>
  
  <pre><code>def download_mp3(url,name):
          opener1 = urllib2.build_opener()
          page1 = opener1.open(url)
          mp3 = page1.read()
          filename = name+'.mp3'
          fout = open(filename, 'wb')
          fout.write(mp3)
          fout.close()
  </code></pre>
  
  <p>This function take an url and a name both as string.
  Then will download and save an mp3 from the url with the name of the variable name.</p>
  
  <p>the url is in the form <a href="http://site/download.php?id=xxxx">http://site/download.php?id=xxxx</a> where xxxx is the id of an mp3</p>
  
  <p>if this id does not exist the site redirects me to another page.</p>
  
  <p>So, the question is: how Can I check if this id exist? I've tried to check if the url exist with a function like this:</p>
  
  <pre><code>def checkUrl(url):
      p = urlparse(url)
      conn = httplib.HTTPConnection(p.netloc)
      conn.request('HEAD', p.path)
      resp = conn.getresponse()
      return resp.status &lt; 400
  </code></pre>
  
  <p>But it's seems not working..</p>
  
  <p>Thank you</p>