Jump to content

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


CT83
 Share

Recommended Posts

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

 

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers

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

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

 

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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!

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 years later...

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
 Share

×
×
  • Create New...