seadoggie01 Posted January 4, 2019 Posted January 4, 2019 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
seadoggie01 Posted January 4, 2019 Author Posted January 4, 2019 I'm sorry, this ended up in the wrong forum. Can a mod help me? 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Moderators JLogan3o13 Posted January 4, 2019 Moderators Posted January 4, 2019 Moved to the appropriate forum. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
TheXman Posted January 4, 2019 Posted January 4, 2019 (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 January 4, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Danp2 Posted January 4, 2019 Posted January 4, 2019 Check the value of @error after the call to ObjCreate. Latest Webdriver UDF Release Webdriver Wiki FAQs
TheXman Posted January 4, 2019 Posted January 4, 2019 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) CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
seadoggie01 Posted January 7, 2019 Author Posted January 7, 2019 (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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
TheXman Posted January 7, 2019 Posted January 7, 2019 (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 January 7, 2019 by TheXman Removed request for actual URL. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
seadoggie01 Posted January 7, 2019 Author Posted January 7, 2019 (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 January 7, 2019 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
TheXman Posted January 7, 2019 Posted January 7, 2019 (edited) This problem may be similar to one that I helped resolve a while back. Edited January 7, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
seadoggie01 Posted January 7, 2019 Author Posted January 7, 2019 (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 January 7, 2019 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
TheXman Posted January 7, 2019 Posted January 7, 2019 You're welcome! CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
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