UrlFetchApp "Exception: Timeout" errors all of a sudden starting April 27, 2021

632 views
Skip to first unread message

Edwin Pankau

unread,
Apr 29, 2021, 4:35:35 PM4/29/21
to Google Apps Script Community
Ever since late morning on April 27, 2021, all of my UrlFetchApp.fetch() calls to my school website's WordPress WooCommerce API are failing with an "Exception: Timeout" error. They had worked fine every hour for years before that.

I can successfully call the same exact API call from Postman with no issues. And, when I look at our WPEngine log, I see a "200" response to the API calls from Google Apps Scripts.

Any ideas what's going on?

Thanks!

Alex

unread,
May 2, 2021, 12:55:03 PM5/2/21
to Google Apps Script Community
So... I would try by creating a simple new script. It is very strange that the Postman (unlike fetch) returns the answer.

Edwin Pankau

unread,
May 2, 2021, 2:29:04 PM5/2/21
to Google Apps Script Community
Good idea. So, I tried just calling UrlFetchApp.fetch("https://google.com"), and it works just fine. Then I tried fetching my school's homepage (not even getting to the WooCommerce API itself), and I get the nasty "Exception: Timeout" error! Makes me think something on the school website's end is blocking calls from google IPs somehow? Postman works just fine for both google.com and my school's homepage URL, of course.

Joshua Snyder

unread,
May 2, 2021, 4:05:37 PM5/2/21
to Google Apps Script Community
I don't have much to add here other than that I've often experienced Postman working whilst calling from a script didn't. In my experience, this was usually related to some CORS issue which Postman somehow got around, not sure that this would be relevant for a Timeout exception though.

Edwin Pankau

unread,
May 3, 2021, 2:05:09 AM5/3/21
to google-apps-sc...@googlegroups.com
Well, it’s a really weird timeout exception, as the error is returned within a few seconds, not after a minute or whatever. Further, as I mentioned in my original post, the server logs on the school website side show a 200 response to the request! So strange.


From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> on behalf of Joshua Snyder <jos...@mindful.ai>
Sent: Sunday, May 2, 2021 2:05:37 PM
To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: [Apps-Script] Re: UrlFetchApp "Exception: Timeout" errors all of a sudden starting April 27, 2021
 
--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/mLCtrK-ZOXE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/c62c750b-e6d9-44f5-b791-e2591b460edan%40googlegroups.com.

Tanaike

unread,
May 3, 2021, 4:22:42 AM5/3/21
to Google Apps Script Community
Can I ask you about the method for executing your script? You execute the script with the script editor or custom function or others?

Edwin Pankau

unread,
May 3, 2021, 8:16:32 AM5/3/21
to google-apps-sc...@googlegroups.com
I execute the script in a custom function that is written in the script editor. It fails when I run it via the script editor’s “debug” tool as well as when I have a time-based trigger call it from Head.

Used to work just fine both ways.


From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> on behalf of Tanaike <kanshi...@gmail.com>
Sent: Monday, May 3, 2021 2:22:42 AM

To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: Re: [Apps-Script] Re: UrlFetchApp "Exception: Timeout" errors all of a sudden starting April 27, 2021
 
Can I ask you about the method for executing your script? You execute the script with the script editor or custom function or others?

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/mLCtrK-ZOXE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.

Tanaike

unread,
May 3, 2021, 8:45:59 PM5/3/21
to Google Apps Script Community
Thank you for replying. Although I'm not sure about your actual situation, for example, is this thread in Stackoverflow related to your situation? https://stackoverflow.com/q/63024346

Edwin Pankau

unread,
May 4, 2021, 3:17:47 PM5/4/21
to Google Apps Script Community
Thanks for the link. While your post there didn't address my situation exactly, it did lead me to calling the API from a function in the sheet itself, which led to me checking the console in the browser, which revealed that the actual API error was NOT a timeout (despite what GAS was saying) and was in fact a 401!

{"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot list resources.","data":{"status":401}}

This didn't make a ton of sense, though, since my authorization had been working for years, and it still worked in Postman. A bit of googling, however, led me to this StackOverflow response from Tony Petruzzi, which miraculously resolved my issue! I have no idea why this would all-of-a-sudden be needed, though.

Needed for WooCommerce API
For future Googlers... I needed to added this to my .htaccess
RewriteRule ^index.php$ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

Reply all
Reply to author
Forward
0 new messages