URLToVar function ERROR_INTERNET_TIMEOUT

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

URLToVar function ERROR_INTERNET_TIMEOUT

19 Oct 2014, 16:41

Hi Guys!

I came across a problem calling a webserver with the URLToVar function where the response time is so long the server throws the following error:
0x80072EE2 ERROR_INTERNET_TIMEOUT
The URLToVar function resides in a script which is launched in two instances quite rapidly inbetween (normally 2 seconds apart). Both instances makes the call. But in this case when first call is made the server seem to stop responding and block any further response. First call timeouts in 30 seconds the second call is launched right after that and the same blocked response occurs until it timeouts after another 30 secs. Now the funny thing, which is very confusing for me, is if using the old URLDownloadToVar function instead i dont get the timeout error. There everything works with no error. So my question is how do they differ and what can I do to make the newer URLToVar function working like the old one (not causing the timeout error)?

New URLToVar function:
Spoiler
Old URLDownloadToVar function:
Spoiler
ahcahc
Posts: 110
Joined: 25 Jul 2014, 23:55

Re: URLToVar function ERROR_INTERNET_TIMEOUT

19 Oct 2014, 21:57

You can suppress comobjct errors with ComObjError(false). This way your script can keep on running.
This is what I use. Found it somewhere and added ComObjError(false) .

Code: Select all

UrlDownloadToVar(URL) {
 ComObjError(false)
 WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 WebRequest.Open("GET", URL)
 WebRequest.Send()
 Return WebRequest.ResponseText
}
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: URLToVar function ERROR_INTERNET_TIMEOUT

20 Oct 2014, 01:58

Hi ahcahc!

ComObjError(false) seem to suppress the actual message coming through but it doesnt have any effect on the timeout this call method causes. Any other way to debug this? I dont wanna use the old urlDownloadtoVar function cuz it has other issues with the downloaded strings, which the new one handles well.

zcooler
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: URLToVar function ERROR_INTERNET_TIMEOUT

20 Oct 2014, 03:41

You can use try/catch to return the error message then see what that tells you...

Code: Select all

UrlDownloadToVar(URL) {
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
try	WebRequest.Open("GET", url, false)
catch	error
	return error.Message
WebRequest.Send()
Return WebRequest.ResponseText
}
Hope it helps

Edit:

or maybe set your own timeout with .SetTimeouts(10000,10000,10000,10000) 10 seconds timeout
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: URLToVar function ERROR_INTERNET_TIMEOUT

20 Oct 2014, 15:01

Hi Blackholyman!

I should explain a little bit more. The webserver is also a recording server which carries out TV-recordings, streaming live-tv and recordings over local network and inet. The webserver part has an API and Im calling the server in order to retrieve the recording status.xml from the API. Im later on parsing the xml for different statuscounters so my script could react depending on these values.

The case where it goes wrong is when two or more recordings finishes at the same time. Each recording fires an after recording task (right after recording finishes). Timings is first after recording task fires 0-1 second after recording stoptime. And second after recording task fires 2 seconds after the first one under normal circumstances. Each after recording task launches their own instance of my ahk script. Right after that the after recording task passes over a command line parameter (absolute path and filename of the finished recording) to the script. My script tries to get the recording status via URLToVar before both after recording tasks finishes. Each after recording task counts as a recording (which is very wrong if you ask me, but i have no choice but to follow the rules stipulated by the program author). After recording status checkup the parameters are processed and after recording task exits.

Now when two URLToVar functions calls the API within that timeframe it gets a hissyfit, but not when using the old URLdownloadToVar function. You showed me how to create a timeout:
"set your own timeout with .SetTimeouts(10000,10000,10000,10000) 10 seconds timeout."

It doesn't work and neither does your code in the codebox. I suspect that is because the AHK built-in COM function already uses a timeout of approximately 20 seconds. That correlates more to the timings im seeing when testing it. I don't know what is triggering the timeout, cuz it works fine as long as calling the API once (when a single recording finishes). Doing it twice within a certain timeframe seem to trigger the COM timeout. This is what im seeing:

URLToVar function timings:
(1) Stoptime recording 1 and 2 - Afterrecording task 1 fires 1 second after stoptime - timeout for 20-30 seconds
(2) After recording task 2 fires 30 seconds after stoptime - timeout again
(3) With my posted URLToVar function the recording server regains idle state (no ongoing recordings) after about 60-65 seconds after stoptime.

With the old URLdownloadToVar timings is:
(1) Stoptime of recording 1 and 2 - Afterrecording task 1 fires 1 second after stoptime - no timeout
(2) After recording task 2 fires 3 seconds after stoptime - no timeout
(3) With my posted URLdownloadToVar function the recording server regains idle state after about 5 seconds after stoptime.

I don't think inserting timeouts would solve anything, there must be some other critera behind the scenes that is controlling this built-in timeout and maybe it can be manipulated somehow or forced to not throw the timeout?
Sorry for the layman terms im using, but don't know any else.

zcooler
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: URLToVar function ERROR_INTERNET_TIMEOUT

20 Oct 2014, 16:20

Hmm Low on time but maybe try doing it asynchronously

Link http://msdn.microsoft.com/en-us/library ... px#SyncApp
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: URLToVar function ERROR_INTERNET_TIMEOUT

21 Oct 2014, 02:50

@Blackholyman, thank you , example seems to work with settimeouts

Code: Select all

;-this thread :
;-http://ahkscript.org/boards/viewtopic.php?f=5&t=4919
;-another thread :
;-http://www.autohotkey.com/board/topic/116747-urltovar-errorhandling/
;-script Radio :
;-http://www.autohotkey.com/board/topic/88864-radio/?hl=%2Bradio#entry563995

vlcx        =%A_programfiles%\VideoLAN\VLC\vlc.exe

;urlx:="http://50.7.70.58:8708"               ;- ok  url     exists
urlx:="http://1.34.113.167:8000"              ;- bad url NOT exists
plx=%urlx%/played.html

xz:=ComObjCreate("WinHttp.WinHttpRequest.5.1")         ;Create the Object
;ComObjError(false)
;xz.Silent := True    ;- script failure = off
xz.SetTimeouts(1000,1000,1000,1000)


try
    {
    xz.Open("GET",plx)                                     ;Open communication
    xz.Send()                                              ;Send the "get" request
    aac:=xz.ResponseText
    if aac=
       {
       msgbox, Error=`nAAC is empty
       exitapp
       }
    }
catch error
    {
    xxx:=error.Message
    msgbox,Error=Catch`n%urlx%`n NOT exists`n------------------------------------------`n%xxx%`n------------------------------------------
    exitapp
    }
msgbox,%aac%
run,%plx%
ifexist,%vlcx%
  run,%vlcx% --one-instance --qt-start-minimized %urlx%,,hide,pid1
exitapp

esc::exitapp
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: URLToVar function ERROR_INTERNET_TIMEOUT

21 Oct 2014, 13:14

Blackholyman wrote:Hmm Low on time but maybe try doing it asynchronously

Link http://msdn.microsoft.com/en-us/library ... px#SyncApp
Yeah, doing it asynchronously works like a charm :mrgreen: Many thanks for pointing me in the right direction, Blackholyman :)

Code: Select all

URLToVar(URL) {
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", URL, true)
WebRequest.Send()
WebRequest.WaitForResponse()
Return WebRequest.ResponseText
}


Regards
zcooler

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], imustbeamoron and 185 guests