相关疑难解决方法(0)

UrlFetchApp.fetch() 似乎没有更改用户代理

尝试使用 Google Apps 脚本从网站获取数据,并将其直接放入电子表格中。fetch 似乎不起作用,而 Python requests 的等效项工作得很好。

Python代码:

page = requests.get("someurl?as_data_structure", headers={'user-agent':'testagent'})
Run Code Online (Sandbox Code Playgroud)

气体代码:

var page = UrlFetchApp.fetch("someurl?as_data_structure", headers={'user-agent':'testagent'});
Run Code Online (Sandbox Code Playgroud)

唯一需要的标头是用户代理,如果我没有包含标头,我从 GAS 代码中得到的错误就是我通常从 Python 代码中得到的错误。我是 js 新手,但据我所知这是正确的方法..?

编辑:现在标题位于正确的位置,但问题仍然存在,与以前的错误完全相同。

var options = {"headers": {"User-Agent": "testagent"}};
var page = UrlFetchApp.fetch("someurl?as_data_structure", options);
Run Code Online (Sandbox Code Playgroud)

user-agent http-headers urlfetch http-status-code-403 google-apps-script

2
推荐指数
1
解决办法
3675
查看次数

UrlFetchApp 上的 500 错误

我正在尝试将产品列表的数据从 Magento API 传递到 Google 电子表格。Magento API 不需要身份验证,因为我以访客身份检索数据。该 API 与RestClient完美配合。

但是,从 Googe Apps Script 获取 REST 资源时出现 500 错误。

Exception: Request failed for
http://mymagentohost/api/rest/products?limit=2
returned code 500. Truncated server response: Service temporary
unavailable (use muteHttpExceptions option to examine full response) 
Run Code Online (Sandbox Code Playgroud)

这是我的 Google Apps 脚本:

function myscript() {
  var url = "http://mymagentohost/api/rest/products?limit=2"
  var response = UrlFetchApp.fetch(url);

  var out = JSON.parse(response.getContentText());
  var doc = SpreadsheetApp.create("Product Info");
  var cell = doc.getRange('a1');
  var index = 0;
  for (var i in out) { …
Run Code Online (Sandbox Code Playgroud)

api rest magento google-apps-script

1
推荐指数
1
解决办法
2408
查看次数