HamidZaeri Posted November 10, 2018 Share Posted November 10, 2018 (edited) How can i handle this Error so my script does not get stuck? (I think it happens when the request is timed out or there is no internet!) --------------------------- AutoIt Error --------------------------- Line 37 (File "C:\Users\Hamid-LT\Desktop\act\BS\BS.au3"): If @error Or StringLen(.ResponseText) < 500 Then ContinueLoop If @error Or StringLen(^ ERROR Error: The requested action with this object has failed. --------------------------- OK --------------------------- Here's my code: With ObjCreate("winhttp.winhttprequest.5.1") .Open("POST", 'https://api.server.ir/get', False) .SetRequestHeader("Content-Type", 'application/x-www-form-urlencoded') .SetRequestHeader("Connection", 'Keep-Alive') .SetRequestHeader("User-Agent", 'okhttp/3.10.0') .SetTimeouts(30000,60000,30000,60000) Do .Send($req[$num][0]) Sleep(Random(100,200)) If @error Or StringLen(.ResponseText) < 500 Then ContinueLoop ; The error come up here! Global $qId = _StringBetween(.ResponseText,'","id":',',"') If @error Or UBound($qId) < 2 Then ContinueLoop Global $act=_StringBetween(.ResponseText,'"aeues":"','","'), $rank=_StringBetween(.ResponseText,'"riae":"','","') If @error Or IsArray($act) = 0 Or IsArray($rank) = 0 Then ContinueLoop Global $cAns = _ArraySearch($aResult,$qId[1],0,0,0,0,0,1) Until @error = 0 And $cAns > -1 $cAns = $aResult[$cAns][12] EndWith That error is not always happening, just sometimes. Edited November 10, 2018 by HamidZaeri Link to comment Share on other sites More sharing options...
Zedna Posted November 11, 2018 Share Posted November 11, 2018 (edited) Simple solution: .Send($req[$num][0]) Sleep(Random(100,200)) If .Status <> '200' Then ContinueLoop ; --> added If @error Or StringLen(.ResponseText) < 500 Then ContinueLoop ; The error come up here! Advanced solution: $objErr = ObjEvent("AutoIt.Error","MyErrFunc") Func MyErrFunc() SetError(1) EndFunc ... .Send(...) If @error Then ContinueLoop Edited November 11, 2018 by Zedna HamidZaeri 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now