0

Trying to add rows to a google spreadsheet from python code throws the error.

Traceback (most recent call last):
  File      "/Users/M/Desktop/s.py",   line 360, in <module>
main()
  File  "/Users/M/Desktop/s.py",  line 346, in main
    client.ProgrammaticLogin()
  File "/Users/M/Desktop/src/gdata/src/gdata/service.py",   line 752, in ProgrammaticLogin
    headers={'Content-Type': 'application/x-www-form-urlencoded'})
  File "/Users/M/Desktop/src/gdata/src/atom/http.py", line   98, in request
    raise atom.http_interface.ContentLengthRequired('Unable to  calculate '
atom.http_interface.ContentLengthRequired: Unable to calculate the     length of the data parameter. Specify a value for Content-Length

I am using this code: https://nirvanatikku.tumblr.com/post/61232391054/inserting-rows-into-a-google-spreadsheet-with

import gdata.spreadsheet.service

email = ''
password = ''
spreadsheet_key = 'test' # key param
worksheet_id = 'od6' # default

def main():
 client = gdata.spreadsheet.service.SpreadsheetsService()
 client.debug = True
 client.email = email
 client.password = password
 client.source = 'test client'
 client.ProgrammaticLogin()

 rows = []
 rows.append({'id':'0','title':'First'})
 rows.append({'id':'1','title':'Second'})

 for row in rows:
     try:
         client.InsertRow(row, spreadsheet_key, worksheet_id)
     except Exception as e:
         print e

 return

The error is thrown at the line "client.ProgrammaticLogin()" Does anyone know how to fix it?

Mauritius
  • 265
  • 1
  • 8
  • 23

1 Answers1

0

Almost a year late, but I found this: http://sapsicoblog.appspot.com/2015/02/GData-ProgrammaticLogin-using-Google-ClientLogin-going-to-stop-working-on-April-20-2015

ProgrammaticLogin() was deprecated April 20, 2015. It is recommended you use oAuth2 instead.

See this: Gdata python Google apps authentication

NMALM
  • 378
  • 2
  • 19