title: Use python Requests to download an compressed tar.gzfile and unzip it using tar
body: <p>I need to use request call to download a tar gz file, I found out that requests.get automatically decompresses the file, I tried to use the solution given <a href="https://stackoverflow.com/a/18364322/2455308">here</a> but when I try to decompress it using tar it says it is not in gzip format. </p>
  
  <p>I tried the following approaches:</p>
  
  <pre><code>response = requests.get(url,auth=(user, key),stream=True)
  if response.status_code == 200:
      with open(target_path, 'wb') as f:
          f.write(response.raw)
  
  if response.status_code == 200:
      with open(target_path, 'wb') as f:
          f.write(response.raw)
  
  raw = response.raw
  with open(target_path, 'wb') as out_file:
      while True:
          chunk = raw.read(1024, decode_content=True)
          if not chunk:
              break
          out_file.write(chunk) 
  </code></pre>
  
  <p>All of the above while decompressing throw the error:</p>
  
  <pre><code>$ tar -xvzf /tmp/file.tar.gz -C /
  
  gzip: stdin: not in gzip format
  tar: Child returned status 1
  tar: Error is not recoverable: exiting now
  </code></pre>
  
  <p>Note: Cannot use <a href="https://stackoverflow.com/a/19602990/2455308">urllib.open</a> as I need authentication etc and I have to use requests library</p>