Vivek Puri
Vivek Puri

Reputation: 171

Accessing google spreadsheet through python

I am trying to connect to my google sheet through python. Here is my code snippet.

#!/usr/bin/python

import time
import gdata.spreadsheet.service

email = '[email protected]'
password = 'mypass'
spreadsheet_key = '1k7XK1FzGcdLdQXs8hfLn6pdWcNZiesmW6Y5eOdxtDwE'
worksheet_id = 'od6'
spr_client = gdata.spreadsheet.service.SpreadsheetsService()
spr_client.email = email
spr_client.password = password

try :
    spr_client.ProgrammaticLogin()
    print "Connected to spreadsheet"
except Exception as e : 
    print "Error connecting to spreadsheet !!! ERROR : ", e

dict = {}
dict['date'] = time.strftime('%m/%d/%Y')
dict['time'] = time.strftime('%H:%M:%S')
print dict

try :
    entry = spr_client.InsertRow(dict, spreadsheet_key, worksheet_id)
    print "Data entered successfully"
except Exception as e :
    print "Could not fill the spreadsheet !!! ERROR : ", e

1. First off all I tried with my correct username and password but it throws an error cElementTree.ParseError: mismatched tag: line 1254, column 4 although my code is of just 30 lines.

2. I tried wrong username and password. It still shows Connected to spreadsheet.

3. On running spr_client.InsertRow(dict, spreadsheet_key, worksheet_id), it is throwing error Could not fill the spreadsheet ERROR : mismatched tag: line 1254, column 4

I have tried all this from this link.

What could be the reason here for this topsy-turvy. Or I am wrong somewhere?

Upvotes: 0

Views: 165

Answers (1)

Caumons
Caumons

Reputation: 9595

Have a look at gspread api, it's much more easy to use and Pythonic: https://github.com/burnash/gspread. I had a lot of troube using gdata.spreadshet until I found the other one.

Upvotes: 1

Related Questions