[英]Python requests, how to calculate Content-Length and add host to convert request from Postman
[英]Trying to add row to google spreadsheet from python. Unable to calculate the length of the data parameter. Specify a value for Content-Length
尝试从 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()”行抛出的 有谁知道如何解决它?
差不多晚了一年,但我发现了这个: http : //sapsicoblog.appspot.com/2015/02/GData-ProgrammaticLogin-using-Google-ClientLogin-going-to-stop-working-on-April-20-2015
ProgrammaticLogin() 已于 2015 年 4 月 20 日弃用。建议您改用 oAuth2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.