[英]TypeError when using Gspread
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
回來了
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')
添加b,但是返回gspread.exceptions.HTTPError: 400: b'Content is not allowed in prolog.'
我該如何解決? 編輯抱歉,我只有一點代碼。 現在讓我增加更多的單詞。
附注:通過包含.get_all_values()方法,可以更容易地將工作表響應對象作為列表讀取:
response = sheet.sheet1.get_all_values()
response.append ( new_row_to_add )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.