Попытка добавить строку в электронную таблицу Google из python. Не удалось вычислить длину параметра данных. Укажите значение для Content-Length

Попытка добавить строки в электронную таблицу Google из кода Python приводит к ошибке.

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

Я использую этот код: 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

Ошибка вылетает в строке "client.ProgrammaticLogin()" Кто-нибудь знает, как это исправить?


person Mauritius    schedule 28.08.2019    source источник


Ответы (1)


С опозданием почти на год, но я нашел это: http://sapsicoblog.appspot.com/2015/02/GData-ProgrammaticLogin-using-Google-ClientLogin-going-to-stop-working-on-April.-20-2015

ProgrammaticLogin() устарел 20 апреля 2015 г. Вместо этого рекомендуется использовать oAuth2.

См. это: Аутентификация приложений Google с помощью Gdata python

person NMALM    schedule 04.08.2020