title: Store file retrieved by HTTP GET
body: <p>I have an API I can retrieve files from. I do this using <code>urllib3</code> in <code>python</code>.</p>
  
  <p>e.g.</p>
  
  <pre class="lang-py prettyprint-override"><code>url = "https://example.com/api/files/13"
  r = http.request('GET', url, headers=headers)
  </code></pre>
  
  <p>where the headers dict contain information for authentication. </p>
  
  <p>When decoding all the data in the response, get the same result as I would expect. I verified this with the response in the network information terminal of my browser:</p>
  
  <pre class="lang-py prettyprint-override"><code>load = json.loads(r.data.decode('utf-8'))
  data = load['data']
  </code></pre>
  
  <p><code>data</code> is at this stage a long string containing characters and digits and looks, depending on the file, similar to <code>dG0seHJheSxtZWRQaG90b24uU04yMDE2LUlSMDA3LkltUmlfRGV0X3BvcyxtZWRQaG90b24uU04yMDE2LUlSMDA3LkltUmlfRGV0X3ZlbCxtZWRQaG90b24uU04yMDE2LUlSMDA3LkltUmlfRGV0X2FjYyxtZWRQaG90b24uU04yMDE2LUlSMDA3LkltUmlfUm5nX3BvcyxtZWRQaG90b24uU04yMDE2LUlSMDA3LkltUmlfUm5nX3ZlbCxtZWRQaG90b...</code>, continuing after the dots. But it is just a csv file.</p>
  
  <p>The only challenge I face now is to store the data to the disc. What I tried so far was:</p>
  
  <pre class="lang-py prettyprint-override"><code>with open(dst_file, 'wb') as out_file:
      out_file.write(data)
  </code></pre>
  
  <p>Instead of the <code>outfile.write(...)</code> I also tried <code>shutil.copyfileobj(r, out_file)</code>, but does not work either.</p>
  
  <p>I guess it depends on the representation of the data I have it present. I guess having it as a string is not really beneficial. But how to store it?</p>
  
  <p><strong>EDIT:</strong>
  One thing that maybe have to be noted: The api url does not contain the file, so the call will be redirected. I tried it with another file from the web, here i did get the desired data immediately presented, when accessing <code>&gt;&gt; r.data</code>.</p>