title: Python: How to download file using range of bytes?
body: <p>I want to download file in multi thread mode and I have following code here:</p>
  
  <pre><code>#!/usr/bin/env python
  
  import httplib
  
  
  def main():
      url_opt = '/film/0d46e21795209bc18e9530133226cfc3/7f_Naruto.Uragannie.Hroniki.001.seriya.a1.20.06.13.mp4'
  
      headers = {}
      headers['Accept-Language'] = 'en-GB,en-US,en'
      headers['Accept-Encoding'] = 'gzip,deflate,sdch'
      headers['Accept-Charset'] = 'max-age=0'
      headers['Cache-Control'] = 'ISO-8859-1,utf-8,*'
      headers['Cache-Control'] = 'max-age=0'
      headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 5.1)'
      headers['Connection'] = 'keep-alive'
      headers['Accept'] = 'text/html,application/xhtml+xml,application/xml,*/*'
      headers['Range'] = ''
  
      conn = httplib.HTTPConnection('data09-cdn.datalock.ru:80')
      conn.request("GET", url_opt, '', headers)
  
      print "Request sent"
  
      resp = conn.getresponse()
      print resp.status
      print resp.reason
      print resp.getheaders()
  
      file_for_wirte = open('cartoon.mp4', 'w')
      file_for_wirte.write(resp.read())
  
      print resp.read()
  
      conn.close()
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Here is output:</p>
  
  <pre><code>Request sent
  200
  OK
  [('content-length', '62515220'), ('accept-ranges', 'bytes'), ('server', 'nginx/1.2.7'), ('last-modified', 'Thu, 20 Jun 2013 12:10:43 GMT'), ('connection', 'keep-alive'), ('date', 'Fri, 14 Feb 2014 07:53:30 GMT'), ('content-type', 'video/mp4')]
  </code></pre>
  
  <p>This code working perfectly however I do not understand through the documentation how to download file using ranges. If you see output of response, which server provides:</p>
  
  <pre><code> ('content-length', '62515220'), ('accept-ranges', 'bytes')
  </code></pre>
  
  <p>It supports range in 'bytes' unit where content size is 62515220</p>
  
  <p>However in this request whole file downloaded. But what I want to do first obtain server information like does this file can be supported using http range queries and content size of file with out downloading? And how I can create http query with range (i.e.: 0~25000)?</p>