I am trying to save a private google spreadsheet into a csv. I have found another thread which has addressed this (Download a spreadsheet from Google Docs using Python), however the answers date back to 2012. There is a solution which I have tried to used, but I am running into errors. This is the code that I am currently using
username = "username" //used the actual username, password and doc-id in the python scriptpassword = "password"
docid = "doc-id"
client = gspread.login(username, password)
spreadsheet = client.open_by_key(docid)
for i, worksheet in enumerate(spreadsheet.worksheets()):
filename = docid + '-worksheet' + str(i) + '.csv'
with open(filename, 'wb') as f:
writer = csv.writer(f)
TypeError: 'str' does not support the buffer interface
In Python 3, open the file in text mode, and set
'' to let the CSV writer control what newlines are written:
with open(filename, 'w', newline='') as f: writer = csv.writer(f) writer.writerows(worksheet.get_all_values())