title: How to download a file from a URL which redirects?
body: <p>I need to download a file using url--><a href="https://readthedocs.org/projects/django/downloads/pdf/latest/" rel="nofollow noreferrer">https://readthedocs.org/projects/django/downloads/pdf/latest/</a></p>
  
  <p>This url redirects to a url with a .pdf file.</p>
  
  <p>How can I download that file with this url using python ?</p>
  
  <p>I've tried :-</p>
  
  <pre><code>import urllib
  def download_file(download_url):
      web_file = urllib.urlopen(download_url)
      local_file = open('some_file.pdf', 'w')
      local_file.write(web_file.read())
      web_file.close()
      local_file.close()
  
  if __name__ == 'main':
      download_file('https://readthedocs.org/projects/django/downloads/pdf/latest/')
  </code></pre>
  
  <p>but this is not working</p>