Jump to content

Recommended Posts

Posted

AutoIT doesn't seem to properly be creating the "winhttp.winhttprequest.5.1" object.

Here's my code:  (yes, it is nearly an exact copy/paste from somewhere else on this forum... but how else would I start learning???)

$restReq = ObjCreate("winhttp.winhttprequest.5.1")
$URL = "__my_organizations_name__.sharepoint.com/system/acct/_api/web/title"
$restReq.Open("GET", "https://" & $URL, False)
$restReq.Send()
$oReceived = $restReq.ResponseText
$oStatusCode = $restReq.Status

When I run this I get this error

(4) : ==> The requested action with this object has failed.:
$restReq.Send()
$restReq^ ERROR

What is really confusing is that:

  • The $URL doesn't matter, it always hits the error
  • Chrome will navigate to the website and show me the XML that is returned (And this also proves that I have permission to use the Rest-api)
  • VBA using very similar code will redirect me to the login page  (I used the CreateObject("winhttp.winhttprequest.5.1") object just fine)

 

Any idea why this won't run in AutoIT?

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Posted

I'm sorry, this ended up in the wrong forum. Can a mod help me? :blink:

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Posted (edited)

@seadoggie01

I ran the code that you posted with a valid URL and it worked fine.  So the problem is not the code, it is something local to the PC that it's running on.  Looking at the error message, it appears that the ObjCreate() function failed for some reason. 

So when you run the same thing using your very similar VB code, on this specific PC, it runs successfully?

This worked fine:

$restReq = ObjCreate("winhttp.winhttprequest.5.1")
$URL = "www.google.com"
;~ $URL = "__my_organizations_name__.sharepoint.com/system/acct/_api/web/title"
$restReq.Open("GET", "https://" & $URL, False)
$restReq.Send()
ConsoleWrite("HTTP Status = " & $restReq.Status & @CRLF)

 

Edited by TheXman
Posted

Run the following snippet and post the output:

$restReq = ObjCreate("winhttp.winhttprequest.5.1")
If @error Then Exit ConsoleWrite(StringFormat("!-> ERROR: Unable to create object.  @error = %i (0x%X)", @error, @error) & @CRLF)

;~ $URL = "__my_organizations_name__.sharepoint.com/system/acct/_api/web/title"
$URL = "www.google.com"
$restReq.Open("GET", "https://" & $URL, False)
$restReq.Send()

ConsoleWrite("HTTP Status = " & $restReq.Status & @CRLF)

 

Posted

(Sorry, was out for the weekend!)

@TheXman I ran your snippet... it did the same thing as last time.  (Literal copy + paste)

"sharepoint.au3" (34) : ==> The requested action with this object has failed.:
$restReq.Send()
$restReq^ ERROR
>Exit code: 1    Time: 1.799

@Danp2 I just tried that, no error there either :/

 Apparently I can create the object and open the request without error, I just can't send it. Could this have something to do with me not having Administrative access?

(And thank you!)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Posted (edited)

 

@seadoggie01

Sorry, my previous snippet wouldn't have worked correctly without a COM error handler because it wouldn't have returned and processed the "if @error".  Can you run this snippet and post the output?  It checks for an error after each statement.  Maybe it will help identify the issue.

Also, do your requests go through a proxy server?

example()

Func example()
    $oComError = ObjEvent("autoit.error", "com_error")

    $restReq = ObjCreate("winhttp.winhttprequest.5.1")
    If @error Then Exit ConsoleWrite(StringFormat("\n!-> ERROR: Unable to create object.  @error = %i (0x%X)\n", @error, @error) & @CRLF)

    ;~ $URL = "__my_organizations_name__.sharepoint.com/system/acct/_api/web/title"
    $URL = "www.google.com"
    $restReq.Open("GET", "https://" & $URL, False)
    If @error Then Exit ConsoleWrite(StringFormat("\n!-> ERROR: Unable to open request.  @error = %i (0x%X)\n", @error, @error))

    $restReq.Send()
    If @error Then Exit ConsoleWrite(StringFormat("\n!-> ERROR: Unable to send request.  @error = %i (0x%X)\n", @error, @error) & @CRLF)

    ConsoleWrite("HTTP Status = " & $restReq.Status & @CRLF)
EndFunc

Func com_error($oError)
    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.scriptline is: " & @TAB & $oError.scriptline & @CRLF)
    Return
EndFunc

 

Edited by TheXman
Removed request for actual URL.
Posted (edited)

@TheXmanHere's what I got: 
 

sharepoint.au3 (41) : ==> COM Error intercepted !
    err.number is:      0x80020009
    err.windescription: Exception occurred.

    err.scriptline is:  41

!-> ERROR: Unable to send request.  @error = -2147352567 (0x80020009)

I think that there isn't a proxy. I checked in IE and the Proxy server setting is not checked. Automatic configuration was checked however, so I have no clue. (Sorry, new to web programming :()

Edit: After checking my history, I found this that shows up occasionally. I don't know if it's helpful

https://company-server-name/B0002D0000N0002N0000F0000S0000R0004/server.ip.address/https://www.websiteITriedGoingTo.com/

 

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Posted (edited)

This problem may be similar to one that I helped resolve a while back.

 

Edited by TheXman
Posted (edited)

Thank you! I will look into it :)

Edit: I can't install or edit the Registry. Ugh. Thank you for your help though! :)

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

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
×
×
  • Create New...