title: Exporting API output response to CSV - Python
body: <p>I am not an expert in Python but I used it to call data from an API. I got a code 200 and printed part of the data but I am not able to export/ save/ write the output (to CSV). Can anyone assist?</p>
  <p>This is my code:</p>
  <pre><code>import requests
  headers = {
      'Accept': 'text/csv',
      'Authorization': 'Bearer ...'
  }
  
  response = requests.get('https://feeds.preqin.com/api/investor/pe', headers=headers)
  print response
  output = response.content
  </code></pre>
  <p>And here is how the data (should be CSV, correct?) looks like:
  <a href="https://i.stack.imgur.com/YdpnK.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>I managed to save it as txt but the output is not usable/ importable (e.g. to Excel). I used the following code:</p>
  <pre><code>text_file = open(&quot;output.txt&quot;, &quot;w&quot;)
  n = text_file.write(output)
  text_file.close()
  </code></pre>
  <p>Thank you and best regards,</p>
  <p>A</p>