CT83

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

13 posts in this topic

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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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
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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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
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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

#9 ·  Posted (edited)

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

Edited by CT83

Share this post


Link to post
Share on other sites

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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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
$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

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

    • Dent
      By Dent
      As the title says. I open IE11 and navigate to a page with the following HTML5 file upload container in Capture0.JPG
      I want to click Add Files but I haven't been able to. Here's the code that handles the Add Files button in Capture.JPG
      _IEGetObjectById and then using _IEAction to click it doesn't work. I can't give access to the actual page unfortunately because it's password protected.
      All suggestions welcome.


    • milos83
      By milos83
      I have one script that creates _IECreateEmbedded and another script that does _IEAttach.
      I do this because when autoit is doing something, the Embedded IE starts stalling (eg jquery progress animation)
      But there is a new problem.
      When IE is having its own process (like in the example above) any _IE command is slow (in the script that Attaches).
      Here is a comparison of when its in separate and when its in same process:
      Separate process _IETagNameGetCollection : 5000ms
      Separate process _IEAction: 850ms
      Same process _IETagNameGetCollection : 1ms
      Same proccess _IEAction: 135ms
       
      If I try to attach to an embedded IE that is done in c#, I get lightning fast results.
      As you can see, _IE functions work very slow when the embedded IE we are attaching to is made in Autoit.
       
      I did a test and if I empty the WHILE loop in IE process I get these results(but the cpu is at 30% as expected):
      Separate process _IETagNameGetCollection : 33ms
      Separate process _IEAction: 13ms
       
      It slows down if you put anything (like GUIGetMsg) in the WHILE loop.
       
      How do I fix this?
       
      Create IE:
      #include <GUIConstantsEx.au3> #include <IE.au3> #include <WindowsConstants.au3> Local $oIE = _IECreateEmbedded() GUICreate("My Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "http://www.autoitscript.com") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ;takes 1ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ;takes 135ms ConsoleWrite(TimerDiff($timer) & @CRLF) While 1 Local $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd  
      Attach to IE:
      #include <IE.au3> Local $oIE = _IEAttach("My Embedded Web control Test", "embedded") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ; 5000ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ; 850ms ConsoleWrite(TimerDiff($timer) & @CRLF)  
       
      attach.au3
      create.au3
    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • toto22
      By toto22
      I'm trying to click on Java Dropbox using IE. However, I'm running into problems. There is a Dropbox "Please Select" with two options "Buy" and "Sell".
      I'm able to click on a drop box (please see code below) but i'm unable to select "Buy" or "Sell"".
      Local $sMyString = "Please Select" ;############ ENTER ############# Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      Please help
       
         
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?