使用Gspread时的TypeError

时间:2016-03-22 20:47:07

标签: python

vagrant up

正在返回

import json import gspread from oauth2client.service_account import ServiceAccountCredentials import math scope = ['https://spreadsheets.google.com/feeds'] credentials = ServiceAccountCredentials.from_json_keyfile_name("nerd test score-4859b437be96.json", scope) gc = gspread.authorize(credentials) sheet = gc.open_by_url('https://docs.google.com/spreadsheets/d/1r5vjJSB76JJq--cmPV6D36PYVFlL4-1N96cBchavawA/edit#gid=365689118') response = sheet.sheet1 print(response.row_count) print(response.cell(2,2)) count = response.row_count -1 response.add_rows(int(1)) sheet2 = gc.open_by_url('https://docs.google.com/spreadsheets/d/1mLq6ofk2rhuPtju8jAGEY15zJdFRw9UL2q9vSw7Vin0/edit#gid=0') result = sheet2.sheet1 print(response.cell(2,10)) def split(cell) : parts=cell.rsplit("'") length=len(parts) print(parts) if length != 3 : parts=cell.rsplit('"') print(parts) return parts

我尝试将b添加到es\gspread\client.py", line 76, in _ensure_xml_header if data.startswith('<?xml'): TypeError: startswith first arg must be bytes or a tuple of bytes, not str,但返回if data.startswith('<?xml')如何解决此问题? 编辑抱歉,我只有一点代码。它让我现在添加更多的单词。

1 个答案:

答案 0 :(得分:0)

附注:通过包含.get_all_values()方法,可以更容易地将工作表响应对象作为列表读取:

response = sheet.sheet1.get_all_values()
response.append ( new_row_to_add )