I've got a simple Google apps script that is fetching a series of RSS feeds:
for (let i = 0; i < rssUrls.length; i++) {
const rssUrl = rssUrls[i];
const response = UrlFetchApp.fetch(rssUrl);
console.log(response.getContentText());
}
The URL that's failing is: http://tenfootpole.org/ironspike/?feed=rss2
The response I get is:
<html><head><title>Error 406 - Not Acceptable</title><head><body><h1>Error 406 - Not Acceptable</h1><p>Generally a 406 error is caused because a request has been blocked by Mod Security. If you believe that your request has been blocked by mistake please contact the web site owner.</p></body></html>
It works fine through the browser or POSTman - & even using the =IMPORTFEED() function in google sheets. Not sure what makes GAS unique?
This is the fix I made after reading Google App Script external API return error 406 & Google Apps Script Blocked by Mod Security Error 406 which seem related.
const options = {
headers: {
Accept: '*/*'
},
'muteHttpExceptions': true
};
const response = UrlFetchApp.fetch(rssUrl, options);
console.log(response.getContentText());
But I still get the same problem. I've tried various combinations of content type, encoding types and languages but I always the same error. I suspect I'm seeing a default response for something else? Any idea what?