Jump to content
CT83

AutoIt Runtime (The requested action with this object has failed)

Recommended Posts

CT83

I send Pushbullet Updates (pushbullet.com) of my script using its native API and i have the following code to do the same, but in some cases my internet connection sometimes stops responding and the notification can't be send  using HTTP.send($sPD) methods,in such cases due to the lack of internet connection a runtime error (The requested action with this object has failed) is generated! This creates problems, as the stability of my script is affected. Is there a way to solve this problem?

Func Send_Pushbullet($spTitle,$sBody,$GFPsh_Tk)
Local $sPD = '{"type": "note", "title": "'&$spTitle&'","body": "'&$sBody&'"}'
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
$oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
$oHTTP.SetRequestHeader("Content-Type", "application/json")
$oHTTP.Send($sPD)
$Result = $oHTTP.ResponseText
ToolTip2("PushBullet :"&$Result)
ToolTip2("PushBullet Sent - "&$spTitle&" : "&$sBody&" "&$GFPsh_Tk)
EndFunc

 

Share this post


Link to post
Share on other sites
water

Yes. Check the return value and @error of each $oHTTP method call and only process the next step when there was no error.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jos

also add an error event handler as described in the helpfile to assist with error handling.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
CT83
Just now, water said:

Yes. Check the return value and @error of each $oHTTP method call and only process the next step when there was no error.

okay, i think u are saying something on the lines of "If @error Then" if i am not mistaken, right? so where should i add these error handling statements ? after http.open ? http.send() ? or after obj create as described in the help file? or is this code right?

Func Send_Pushbullet($spTitle,$sBody,$GFPsh_Tk)
Local $sPD = '{"type": "note", "title": "'&$spTitle&'","body": "'&$sBody&'"}'
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
If Not @error Then
$oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
$oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
$oHTTP.SetRequestHeader("Content-Type", "application/json")
$oHTTP.Send($sPD)
$Result = $oHTTP.ResponseText
ToolTip2("PushBullet :"&$Result)
ToolTip2("PushBullet Sent - "&$spTitle&" : "&$sBody&" "&$GFPsh_Tk)
Else
ConsoleWrite("Ie error")
EndIf   
EndFunc

 

Share this post


Link to post
Share on other sites
water

Something like this. It exits after an error and displays a MsgBox:

Func Send_Pushbullet($spTitle, $sBody, $GFPsh_Tk)
    
    Local $sPD = '{"type": "note", "title": "' & $spTitle & '","body": "' & $sBody & '"}'
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    If @error Then Exit MsgBox(0, "Error", "ObjCreate returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
    If @error Then Exit MsgBox(0, "Error", "Open method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.SetRequestHeader("Content-Type", "application/json")
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Send($sPD)
    If @error Then Exit MsgBox(0, "Error", "Send method returned @error = " & @error & " and @extended = " & @extended)
    $Result = $oHTTP.ResponseText
    ToolTip2("PushBullet :" & $Result)
    ToolTip2("PushBullet Sent - " & $spTitle & " : " & $sBody & " " & $GFPsh_Tk)

EndFunc   ;==>Send_Pushbullet

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
CT83
6 minutes ago, water said:

Something like this. It exits after an error and displays a MsgBox:

Func Send_Pushbullet($spTitle, $sBody, $GFPsh_Tk)
    
    Local $sPD = '{"type": "note", "title": "' & $spTitle & '","body": "' & $sBody & '"}'
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    If @error Then Exit MsgBox(0, "Error", "ObjCreate returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
    If @error Then Exit MsgBox(0, "Error", "Open method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.SetRequestHeader("Content-Type", "application/json")
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Send($sPD)
    If @error Then Exit MsgBox(0, "Error", "Send method returned @error = " & @error & " and @extended = " & @extended)
    $Result = $oHTTP.ResponseText
    ToolTip2("PushBullet :" & $Result)
    ToolTip2("PushBullet Sent - " & $spTitle & " : " & $sBody & " " & $GFPsh_Tk)

EndFunc   ;==>Send_Pushbullet

 

oh okay!  thanks alot! that was all i needed!

Share this post


Link to post
Share on other sites
water

Could you please just "Reply to this topic" without quoting the whole post? Makes your thread easier to read and saves a lot of space. And I know what I posted before ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

BTW: If you run AutoIt > 3.3.12.0 then you need to add a COM error handler as suggested by Jos above. Else your script will always crash when a COM error is being detected.
Check the help file for ObjEvent and you will find an example.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
CT83

Okay sure i will try that... gimme a sec

Edited by CT83

Share this post


Link to post
Share on other sites
CT83

yeah, i looked up in the help file, but i failed to understand how it works, I am a real beginner :(could u please illustrate the same with my example? or anything similar? 

I am not trying to get you to do my work, its just that i dont really get the example in the helpfile. Sorry for inconvenice :( 

-newbie 

Share this post


Link to post
Share on other sites
water

Quite easy:

Func Send_Pushbullet($spTitle, $sBody, $GFPsh_Tk)
    
    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    Local $sPD = '{"type": "note", "title": "' & $spTitle & '","body": "' & $sBody & '"}'
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    If @error Then Exit MsgBox(0, "Error", "ObjCreate returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
    If @error Then Exit MsgBox(0, "Error", "Open method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.SetRequestHeader("Content-Type", "application/json")
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Send($sPD)
    If @error Then Exit MsgBox(0, "Error", "Send method returned @error = " & @error & " and @extended = " & @extended)
    $Result = $oHTTP.ResponseText
    ToolTip2("PushBullet :" & $Result)
    ToolTip2("PushBullet Sent - " & $spTitle & " : " & $sBody & " " & $GFPsh_Tk)

EndFunc   ;==>Send_Pushbullet

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
CT83
$oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Okay!!! Finally got it! Declare this (code) as Global at the top of my script. Then add a MsgBox and stuff in _ErrFunc ! right! o:)

Thanks all. You are awesome! :lmao:

Share this post


Link to post
Share on other sites
water

Ops. Copy & Paste error in my post. I missed to post this line :(


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • FMS
      By FMS
      Hello,
      I try to get all the text from a news site around a subject.
      The first run I get all the text inside a attribute in an array.
      When i try to go back and reload another page it chrashes and think it because "$oIE.GoBack"
      I couldn't find anything in the help/forum around this subject.
      Do I need to reload the $oIE or something afther an X.GoBack?
      The error i got is :
      if $oTag2.GetAttribute("class") == "NewsDetail" Then if $oTag2^ ERROR I'm not shure why I got this error, maybe someone could explain?
      Also I'm open for some pointers in this test script because I'm pretty new in working whit the IE.UDF
      Maybe there is an simpler way to get the same results?

      test script:
      #include <IE.au3> #include <MsgBoxConstants.au3> #include <Array.au3> HotKeySet("{ESC}", "Terminate") Global $oIE = _IECreate("https://www.iex.nl/Zoeken/Nieuws.aspx?q=air%20france") ;get first subject Global $oLink1 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl00_linkNews") Sleep(500) _IEAction($oLink1, "click") Sleep(500) Global $oTags = _IETagNameGetCollection($oIE, "div") Global $aResults[1] For $oTag In $oTags if $oTag.GetAttribute("class") == "NewsDetail" Then _ArrayAdd($aResults, $oTag.innerTEXT) EndIf Next $aResults[0] = UBound($aResults) - 1 _ArrayDisplay($aResults, "Episodelist") ConsoleWrite($aResults[1] & @CRLF) $oIE.GoBack ;get second subject Global $oLink2 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl01_linkNews") Sleep(500) _IEAction($oLink2, "click") Sleep(500) Local $oTags2 = _IETagNameGetCollection($oIE, "div") Local $aResults2[1] For $oTag2 In $oTags2 if $oTag2.GetAttribute("class") == "NewsDetail" Then _ArrayAdd($aResults2, $oTag2.innerTEXT) EndIf Next $aResults2[0] = UBound($aResults2) - 1 ConsoleWrite($aResults2[1] & @CRLF) Func Terminate() _IEQuit($oIE) Exit EndFunc ;==>Terminate  
    • SkysLastChance
      By SkysLastChance
      I am having a hard time understanding why this is not working. I was hoping some one could help explain it to me. 
      $tags = $oIE.document.GetElementsByTagName("input") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "fTs-p3298-l0 wplEditControl" Then $target = $tag ExitLoop EndIF Next MsgBox(0,"",$target) If $target = "fTs-p3298-l0 wplEditControl" THEN MsgBox(0,"","itworked") I have tried 
       MsgBox(0,"",$target.Attribute)  MsgBox(0,"",$target.Value)  MsgBox(0,"",$target.InnerText) I would expect to see this in the msgbox
      fTs-p3298-l0 wplEditControl  
    • SkysLastChance
      By SkysLastChance
      I am trying to grab the id "in2xk_26" however it the characters before the underscore always change. (in the name too)
      Is there a way I can find a id or name by the last 3 charcters?
      Using something like "stringright?"
      So I would want to search for just "_26" in this case.
      This is assuming that there are no other _26
       

      #include <Excel.au3> #include <IE.au3> #include <GUIConstantsEx.au3> Global $iMousespeed = 25,$target = "",$TagName = "",$Value = "",$Atrribute = "" $oIE = _IEAttach("MEDITECH") $TagName = "input" $Value = "in2xk_26" $Attribute = "id" $tags = $oIE.document.GetElementsByTagName($TagName) ;TagName ------ MAKE SURE TO NAME THESE For $tag in $tags $class_value = $tag.GetAttribute($Attribute) ;Attribute ------ MAKE SURE TO NAME THESE If string($class_value) = $Value Then ;Value ------ MAKE SURE TO NAME THESE $target = $tag $iScreenX = _IEPropertyGet($target, "screenx") $iScreenY = _IEPropertyGet($target, "screeny") $iWidth = _IEPropertyGet($target, "width") $iHeight = _IEPropertyGet($target, "height") $oMouseCords = MouseMove($iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, $iMousespeed) MouseClick($MOUSE_CLICK_LEFT) ExitLoop EndIf Next  
       
    • SkysLastChance
      By SkysLastChance
      I was wondering how I read data inside of a iframe. I would like to be able to click something inside a iframe. However, I can't even find the tag. 
      The id and name change all the time so I can't use those. 
      The code highlighted in blue is what I am trying to click. (second picture)
      Here is what I have tried.
      $target = "" $tags = $oIE.document.GetElementsByTagName("div") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "s_92 altstyle s_93 s_94" Then $target = $tag ConsoleWrite("Tag Found " & $target.outerText&@CRLF) ExitLoop EndIf Next  

       
       

    • SkysLastChance
      By SkysLastChance
       
      WinActivate("MEDITECH - Internet Explorer") Sleep (500) $oIE = _IEAttach("MEDITECH") $oDiv1 = _IEGetObjById($oIE, "sysmenu-searchbarbutton") _IEAction($oDiv1, "click") I am just trying to click the little magnifying glass, next to the gear button with no luck. I was hoping someone might have an idea why this is not working?
       

×