Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7128001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:05:33+00:00 2026-05-28T11:05:33+00:00

Can you produce a Python example of how to download a Google Sheets spreadsheet

  • 0

Can you produce a Python example of how to download a Google Sheets spreadsheet given its key and worksheet ID (gid)? I can’t.

I’ve scoured versions 1, 2 and 3 of the API. I’m having no luck, I can’t figure out their compilcated ATOM-like feeds API, the gdata.docs.service.DocsService._DownloadFile private method says that I’m unauthorized, and I don’t want to write an entire Google Login authentication system myself. I’m about to stab myself in the face due to frustration.

I have a few spreadsheets and I want to access them like so:

username = 'mygooglelogin@gmail.com'
password = getpass.getpass()

def get_spreadsheet(key, gid=0):
    ... (help!) ...

for row in get_spreadsheet('5a3c7f7dcee4b4f'):
    cell1, cell2, cell3 = row
    ...

Please save my face.


Update 1: I’ve tried the following, but no combination of Download() or Export() seems to work. (Docs for DocsService here)

import gdata.docs.service
import getpass
import os
import tempfile
import csv

def get_csv(file_path):
  return csv.reader(file(file_path).readlines())

def get_spreadsheet(key, gid=0):
  gd_client = gdata.docs.service.DocsService()
  gd_client.email = 'xxxxxxxxx@gmail.com'
  gd_client.password = getpass.getpass()
  gd_client.ssl = False
  gd_client.source = "My Fancy Spreadsheet Downloader"
  gd_client.ProgrammaticLogin()

  file_path = tempfile.mktemp(suffix='.csv')
  uri = 'http://docs.google.com/feeds/documents/private/full/%s' % key
  try:
    entry = gd_client.GetDocumentListEntry(uri)

    # XXXX - The following dies with RequestError "Unauthorized"
    gd_client.Download(entry, file_path)

    return get_csv(file_path)
  finally:
    try:
      os.remove(file_path)
    except OSError:
      pass
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:05:33+00:00Added an answer on May 28, 2026 at 11:05 am

    In case anyone comes across this looking for a quick fix, here’s another (currently) working solution that doesn’t rely on the gdata client library:

    #!/usr/bin/python
    
    import re, urllib, urllib2
    
    class Spreadsheet(object):
        def __init__(self, key):
            super(Spreadsheet, self).__init__()
            self.key = key
    
    class Client(object):
        def __init__(self, email, password):
            super(Client, self).__init__()
            self.email = email
            self.password = password
    
        def _get_auth_token(self, email, password, source, service):
            url = "https://www.google.com/accounts/ClientLogin"
            params = {
                "Email": email, "Passwd": password,
                "service": service,
                "accountType": "HOSTED_OR_GOOGLE",
                "source": source
            }
            req = urllib2.Request(url, urllib.urlencode(params))
            return re.findall(r"Auth=(.*)", urllib2.urlopen(req).read())[0]
    
        def get_auth_token(self):
            source = type(self).__name__
            return self._get_auth_token(self.email, self.password, source, service="wise")
    
        def download(self, spreadsheet, gid=0, format="csv"):
            url_format = "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=%s&exportFormat=%s&gid=%i"
            headers = {
                "Authorization": "GoogleLogin auth=" + self.get_auth_token(),
                "GData-Version": "3.0"
            }
            req = urllib2.Request(url_format % (spreadsheet.key, format, gid), headers=headers)
            return urllib2.urlopen(req)
    
    if __name__ == "__main__":
        import getpass
        import csv
    
        email = "" # (your email here)
        password = getpass.getpass()
        spreadsheet_id = "" # (spreadsheet id here)
    
        # Create client and spreadsheet objects
        gs = Client(email, password)
        ss = Spreadsheet(spreadsheet_id)
    
        # Request a file-like object containing the spreadsheet's contents
        csv_file = gs.download(ss)
    
        # Parse as CSV and print the rows
        for row in csv.reader(csv_file):
            print ", ".join(row)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Python: Date Ordinal Output? In Python time.strftime can produce output like Thursday
Is there a tool available that can produce an HTML summary list of perl
I'm writing a small .NET application that can produce SWF files, and I need
In native development, you can produce libraries - .so, .dll etc - that other
How can we produce the effect of the red line under a bad spelling
How can I produce a messagebox in a C# Win Forms application that displays
I have a list with 15 numbers. How can I produce all 32,768 combinations
Say I have a.so and b.so. Can I produce c.so as a single shared
Can a C++ compiler produce a not so good binary? You can think here
Can you program/configure Visual Studio to produce custom intellisense for your own server controls.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.