title: Export salesforce report as CSV
body: <p>I'm trying to pull salesforce reports through python. I've tried this approach:</p>
  
  <pre><code>import requests
  
  l = requests.get('sfinstanceurl/?un=user&amp;pw=passw')
  
  report = requests.get('sfinstanceurl/reportid?view=d&amp;snip&amp;export=1&amp;enc=UTF-8&amp;xf=csv',cookies=l.cookies)
  
  print(report.content)
  </code></pre>
  
  <p>Also this one:</p>
  
  <pre><code>def sfdc_to_pd(reportid):
  
      login_data = {'un': 'your_username', 'pw': 'your_password'}
  
      with requests.session() as s:
      s.get('https://your_instance.salesforce.com', params = login_data)
      d = requests.get("https://your_instance.salesforce.com/{}?export=1&amp;enc=UTF-8&amp;xf=csv".format(reportid), headers=s.headers, cookies=s.cookies)
      lines = d.content.splitlines()
      reader = csv.reader(lines)
      data = list(reader)
      data = data[:-7]
      df = pd.DataFrame(data)
      df.columns = df.iloc[0]
      df = df.drop(0)
      return df
      print df
  </code></pre>
  
  <p>And for both, when i print the content I get this (even though the status response is always 200):</p>
  
  <pre><code>b'\r\n&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;\n&lt;html&gt;\n&lt;head&gt;\n    &lt;meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"&gt;\n\n\n\n\n\n&lt;script&gt;\nif (this.SfdcApp &amp;&amp; this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect(\'sfinstanceurl?ec=302&amp;startURL=%2F00O0m000000JzRc%3Fview%3Dd%26enc%3DUTF-8%26export%3D1%26xf%3Dcsv%26snip%3D\'); }  else \nif (window.location.replace){ \nwindow.location.replace(\'sfinstanceurl?ec=302&amp;startURL=%2F00O0m000000JzRc%3Fview%3Dd%26enc%3DUTF-8%26export%3D1%26xf%3Dcsv%26snip%3D\');\n} else {;\nwindow.location.href =\'sfinstanceurl?ec=302&amp;startURL=%2F00O0m000000JzRc%3Fview%3Dd%26enc%3DUTF-8%26export%3D1%26xf%3Dcsv%26snip%3D\';\n} \n&lt;/script&gt;\n\n&lt;/head&gt;\n\n\n&lt;/html&gt;\n\n\n\n\n\n&lt;!-- Body events --&gt;\n&lt;script type="text/javascript"&gt;function bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken="null";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}&lt;/script&gt;\n\t\t\t\n&lt;/body&gt;\n&lt;/html&gt;\n\n\n&lt;!--\n...................................................................................................\n...................................................................................................\n...................................................................................................\n...................................................................................................\n--&gt;\n'
  </code></pre>
  
  <p>My company uses SSO, so security tokens are not something i have to try a different approach. Am I missing something? Why do I not get the report in the content?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I also just tried this approach:</p>
  
  <pre><code>from simple_salesforce import Salesforce
  import requests
  import base64
  import json
  
  sf = Salesforce(username=    #login
                  ,password=  # password
                  ,security_token= # token )
  
  print "get sid ", sf.session_id
  
  response = requests.get("https://instancename/reportid?view=d&amp;snip&amp;export=1&amp;enc=UTF-8&amp;xf=csv",
                    headers = sf.headers, cookies = {'sid' : sf.session_id})
  
  response.content
  </code></pre>
  
  <p>It still returns the same HTML object.</p>