gpt4 book ai didi

javascript - 使用基本身份验证的 Google Apps 脚本中的 UrlFetchApp.fetch 出现意外错误

转载 作者:行者123 更新时间:2023-12-03 14:40:11 25 4
gpt4 key购买 nike

我在 Google Apps Script 中有以下代码,它使用基本身份验证通过 HTTP 从网页中检索 CSV 数据并将其放入电子表格中:CSVImport.gs

function parseCSVtoSheet(sheetName, url)
{
// Credentials
var username = "myusername";
var password = "mypassword";
var header = "Basic " + Utilities.base64Encode(username + ":" + password);

// Setting the authorization header for basic HTTP authentication
var options = {
"headers": {
"Authorization": header
}
};

// Getting the ID of the sheet with the name passed as parameter
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName(sheetName);
var sheetId = sheet.getSheetId();

// Getting the CSV data and placing it into the spreadsheet
var csvContent = UrlFetchApp.fetch(url, options).getContentText();
var resource = {requests: [{pasteData: {data: csvContent, coordinate: {sheetId: sheetId}, delimiter: ","}}]};
Sheets.Spreadsheets.batchUpdate(resource, spreadsheet.getId());
}
这一直在工作,直到最近我在 UrlFetchApp.fetch 上随机收到以下错误线: Exception: Unexpected error: http://www.myurl.com/data/myfile.csv (line 21, file "CSVImport")我努力了:
  • 将凭据直接放在 URL 中,而不是放在 Authorization header 中(我收到一个不同的错误,说“不允许登录信息”)。
  • 当我将凭据传递到 headers 对象时,将凭据编码为 base64(不起作用,同样的错误)。
  • 完全删除身份验证(可以预见的是,我从 HTTP 页面收到了 401 响应)。

  • 我不确定还有什么可以尝试的,以及为什么这会突然突然崩溃。有什么建议吗?

    最佳答案

    这与一个新错误有关,请参阅 here
    许多用户都受到了影响,我建议您为该问题“加注星标”以提高知名度并有望加快这一进程。

    关于javascript - 使用基本身份验证的 Google Apps 脚本中的 UrlFetchApp.fetch 出现意外错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65233801/

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