title: How to implement a CURL -o in Python using request or aoihttp
body: <p>I need to do a get to a URL with certain Headers and Parameters in my python code and then write to an excel file. I am trying the below code but getting the below error when I try to open the excel file. Also given below is a redacted version of a CURL I use to test this API endpoint with success that I cannot replicate in my python code</p>
  
  <p>Python Code: </p>
  
  <pre><code>import requests
  rheaders = {
              "Content-type": "application/json",
               "Accept": "application/json",
               "Authorization": "Token XXX",
  }
  url = "https://api.YYY"
  r = requests.get(url, headers=rheaders)
  with open("test.xlsx" , mode="wb") as output:
      output.write(r.content)
  </code></pre>
  
  <p>Error: Excel cannot open the file 'test.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.</p>
  
  <p>The assosciated CURL that runs fine in osx terminal and writes the output file without errors</p>
  
  <pre><code>curl -H "Accept: application/json; indent=4" -H 'Content-Type: application/json' -H 'Authorization: Token XXX' https://api.YYY --output ~/Downloads/output.xlsx
  </code></pre>
  
  <p>I have tried replacing the content-type header with this:</p>
  
  <pre><code>Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  </code></pre>
  
  <p>No luck. Any suggestions? The above is my attempt with python library requests. I have also tried using aiohttp</p>