title: How do you save a Google Sheets file as CSV from Python 3 (or 2)?
body: <p>I am looking for a simple way to save a csv file originating from a published Google Sheets document? Since it's published, it's accessible through a direct link (modified on purpose in the example below).</p>
  
  <p>All my browsers will prompt me to save the csv file as soon as I launch the link.</p>
  
  <p>Neither:</p>
  
  <pre><code>DOC_URL = 'https://docs.google.com/spreadsheet/ccc?key=0AoOWveO-dNo5dFNrWThhYmdYW9UT1lQQkE&amp;output=csv'    
  
  f = urllib.request.urlopen(DOC_URL)
  cont = f.read(SIZE)
  f.close()
  cont = str(cont, 'utf-8')
  print(cont)
  </code></pre>
  
  <p>, nor:</p>
  
  <pre><code>req = urllib.request.Request(DOC_URL)
  req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1284.0 Safari/537.13')
  f = urllib.request.urlopen(req)
  print(f.read().decode('utf-8'))
  </code></pre>
  
  <p>print anything but html content. </p>
  
  <p>(Tried the 2nd version after reading this other post: <a href="https://stackoverflow.com/questions/12842341/download-google-docs-public-spreadsheet-to-csv-with-python">Download google docs public spreadsheet to csv with python</a> .)</p>
  
  <p>Any idea on what I am doing wrong? I am logged out of my Google account, if that worths to anything, but this works from any browser that I tried. As far as I understood, the Google Docs API is not yet ported on Python 3 and given the "toy" magnitude of my little project for personal use, it would not even make too much sense to use it from the get-go, if I can circumvent it. </p>
  
  <p>In the 2nd attempt, I left the 'User-Agent', as I was thinking that maybe requests thought as coming from scripts (b/c no identification info is present) might be ignored, but it didn't make a difference.</p>