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
is returning
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
I tried adding b to if data.startswith('<?xml')
but that returns gspread.exceptions.HTTPError: 400: b'Content is not allowed in prolog.'
How do I fix this? Edit sorry that I had only the one bit of code. it is making me add more words now.
Side note: It may be easier to read the sheet response object as a list by including the .get_all_values() method :
response = sheet.sheet1.get_all_values()
response.append ( new_row_to_add )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.