0

I have a simple publicly shared and published google sheet, I am trying to print the title of the sheet using gdata client in python , the sheet exists and I can read it via pandas but gdata is giving 404 error. I have created a working test case to show the issue, contains the URLs to the sheet as well.

import requests

# #Sheet URL:
sheet_url = 'https://docs.google.com/spreadsheets/d/1XFA9PjZySw9CjCoV8N--kNnUpWDnomUmwbXyQenz1AI/edit?usp=sharing'
status = requests.get(sheet_url)
print('Status response code : {}'.format(status))
print('This confirms that the sheet exists')
#print(status.headers)
print('')

try:
  from gdata.spreadsheet.service import SpreadsheetsService
  
  key ='1XFA9PjZySw9CjCoV8N--kNnUpWDnomUmwbXyQenz1AI'
  
  client = SpreadsheetsService()
  feed = client.GetWorksheetsFeed(key, visibility='public', projection='basic')
  for sheet in feed.entry:
    print(sheet.title.text)
except Exception as e: 
  print(e)
  print('')
  print('G data failed I really do not know why, trying with pandas so show that sheet exists')
  import pandas as pd
  
  #Sheet published as csv URL:
  pathtoCsv = r'https://docs.google.com/spreadsheets/d/e/2PACX-1vSXJPI2FyxOUr1UsyJ4uXPPIY3HOxaihUmfGbWxH-yXtdu86tBDH2uMxL67UtCKyhjZGpJXzJcm0-1l/pub?gid=0&single=true&output=csv'

  df = pd.read_csv(pathtoCsv)
  print('')
  print('Pandas read:')
  print('')
  print(df)

You can run this code to see the issue. need to have gdata, requests and pandas.

  • If there is anyway to read a publicly shared spreadsheet , without logging using gdata? – Ambika Yadav Aug 26 '21 at 05:39
  • `gdata` has not been under active maintenance, its support for Python 3 may not be as good. You can try using an older version of Python 2 to run this code. Have you tried using the official [Google Sheets API](https://developers.google.com/sheets/api/quickstart/python)? – Divyesh Peshavaria Aug 26 '21 at 05:55

0 Answers0