gpt4 book ai didi

python - gspread 批量更新单元格,50k 限制?

转载 作者:行者123 更新时间:2023-11-28 17:41:04 26 4
gpt4 key购买 nike

我一直在使用 gspread 一段时间没有问题。我最近在更新到 Google 表格时检查了 50000 个单元格。我得到一个

请求中的文件“build\bdist.win32\egg\gspread\httpsession.py”,第 81 行
引发 HTTPError(响应)
HTTP错误

是不是更新时间太长导致连接超时?

我要更新的单元格范围是 A1:CL560。我将输出切成 50000 个单元格,代码运行良好。

我使用的代码就是github上引用的代码:

cell_list = worksheet.range('A1:C7')

for cell in cell_list:
cell.value = 'O_o'

# Update in batch
worksheet.update_cells(cell_list)

50000 单元格下似乎一切正常。不确定该怎么做。

这是错误:错误:[Errno 10054] 现有连接被远程主机强行关闭

我已尝试保持连接,但仍然无法正常工作。

最佳答案

有点晚了,但我遇到了这个问题,我通过分块设置值解决了这个问题,请参阅下面我使用 GoogleScript 的解决方案。这有点令人费解,但我一直在弄清楚:)

 function importtxt(url) {   
var parameters = {method : "get", payload : "", muteHttpExceptions: true, validateHttpsCertificates: false};
var result = UrlFetchApp.fetch(url, parameters);
var responseCode = result.getResponseCode();

var contents = result.getContentText().toString().replace("^[^<]*", "");
var line = contents.split("\n");

var j = 0;
var start = 1;
var chunk = new Array();
var chunksize = 5000;
var rows = contents.length;

var ImportData = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ImportData");
var range = ImportData.getRange("B2:B").clearContent();

for (var i = 0; i < rows; i++) {
if ( line[i]) {
chunk.push([line[i]]);
j++;
if ( j > chunksize || i == contents.length ) {
j += start - 1;
var end = j;
Logger.log("writing chunk to " + start + " : " + j + " : " + chunk.length);
// write chunk to sheet, i will denote the start
var range = ImportData.getRange("A" + start + ":A" + j);
range.setValues(chunk);
// set variables for next run
start = end + 1;
var chunk = new Array();
j = 0;
}
}
}
Logger.log("finished - last row was " + end + " but last row should have been " + contents.length);
if ( j < i ) {
j += start - 1;
var end = j;
Logger.log("writing end chunk to " + start + " : " + j + " : " + chunk.length);
// write chunk to sheet, i will denote the start
var range = ImportData.getRange("A" + start + ":A" + j);
range.setValues(chunk);
}
return;
}

关于python - gspread 批量更新单元格,50k 限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24196879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com