Unexpected Error Google Apps Script Fetch

跟風遠走 提交于 2019-12-11 01:26:07

问题


I get an "Unexpected Error" from the following function:

function getBomgarFeedbackXML(){
  var url = "https://help.tradingtechnologies.com/api/reporting.ns?" + 
            "username=xxxxxx&password=xxxxxx&generate_report=SupportCustExitSurvey&" + 
            "start_date=2000-01-01&duration=0&report_type=rep&id=all";
  var response = UrlFetchApp.fetch(url).getContentText();
  Logger.log(response);
  return(Xml.parse(response, true));
}

The line that causes the error is:

var response = UrlFetchApp.fetch(url).getContentText();
  1. I am able to fetch the URL programatically using other scripting languages, such as python
  2. I have tried fetching the URL in my browser which I was able to do successfully
  3. I can fetch "http://www.google.com" from Google apps script successfully
  4. I get the following warning when navigating to the URL in chrome, could this be related to the issue ?

Any help is appreciated Thanks


回答1:


The last bit with the untrusted certs is the big clue here. Seems like the SSL cert associated with 'help.tradingtechnologies.com'is not valid or signed by a trusted CA per the Google Data Centers (from where the UrlFetch calls originate).

To work around this try this line of code instead of your UrlFetch call. Note the additional option for validateHttpsCertificates documented here.

var response = UrlFetchApp.fetch(url, {'validateHttpsCertificates':false}).getContentText();


来源:https://stackoverflow.com/questions/13508326/unexpected-error-google-apps-script-fetch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!