python gspread-要求在范围内写作,但尝试写入其他行
遇到此代码的问题,该代码将数组转换为DF,然后更新了一个Google表,其中有更多的数据在一周前起作用:
df2 = pd.DataFrame(data, columns=['Col1', 'Col2', 'Col3', 'Col4',
'Col5', 'Col6', 'Col7', 'Col8'])
gc = gs.service_account(filename=CloudPathCredentials)
ws = gc.open("Spreadsheetname").worksheet("Sheet1")
firsthold = holder[0]
lasthold = holder[-1]
cellmatch1 = ws.find(firsthold)
cellmatch2 = ws.find(lasthold)
begrow = str(cellmatch1.row)
endrow = str(cellmatch2.row)
begrange = "A" + begrow
endrange = "H" + endrow
fullrange = begrange + ":" + endrange
values = df2.values.tolist()
ws.update(fullrange, values)
现在,由于某种原因,数据结束后,它正在尝试写入1行,并引发错误:
gspread.exceptions.APIError: {'code': 400, 'message': 'Requested writing within range [Sheet1!1757:1890], but tried writing to row [1891]', 'status': 'INVALID_ARGUMENT'}
Running into an issue with this code which converted an array into a df then updated a google sheet with more recent data that worked about a week ago:
df2 = pd.DataFrame(data, columns=['Col1', 'Col2', 'Col3', 'Col4',
'Col5', 'Col6', 'Col7', 'Col8'])
gc = gs.service_account(filename=CloudPathCredentials)
ws = gc.open("Spreadsheetname").worksheet("Sheet1")
firsthold = holder[0]
lasthold = holder[-1]
cellmatch1 = ws.find(firsthold)
cellmatch2 = ws.find(lasthold)
begrow = str(cellmatch1.row)
endrow = str(cellmatch2.row)
begrange = "A" + begrow
endrange = "H" + endrow
fullrange = begrange + ":" + endrange
values = df2.values.tolist()
ws.update(fullrange, values)
now it is attempting to write to 1 row after the data ends for some reason and throws the error:
gspread.exceptions.APIError: {'code': 400, 'message': 'Requested writing within range [Sheet1!1757:1890], but tried writing to row [1891]', 'status': 'INVALID_ARGUMENT'}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论