pete_wilde Posted October 2, 2019 Posted October 2, 2019 Hi Guys, I am trying to convert a python script to AutoIT, but it is not returning any data. My aim is to eventually have a script which sends me an email whenever a goal is scored in the English Premiership. Is there any guru who can have a quick look over the below script and see if there are any obvious errors? To use a football analogy, I think that I have hit the bar a couple of times, but not yet found the back of the net! expandcollapse popup#cs ---------------------------------------------------------------------------- PYTHON CODE: import requests import json endpoint = "https://api.betfair.com/exchange/betting/rest/v1.0/" header = { 'X-Application' : 'APP_KEY_HERE', 'X-Authentication' : 'SESSION_TOKEN_HERE' ,'content-type' : 'application/json' } json_req='{"filter":{ }}' url = endpoint + "listEventTypes/" response = requests.post(url, data=json_req, headers=header) print json.dumps(json.loads(response.text), indent=3) #ce ---------------------------------------------------------------------------- #include <WinHttp.au3> Opt("MustDeclareVars", 1) Opt("TrayIconDebug", 1) Global $sAddress = 'https://api.betfair.com/exchange/betting/json-rpc/v1/' Global $sPostData = 'https://api.betfair.com/exchange/betting/json-rpc/v1/listEventTypes/' Global $sAppKey = '4YpsEhdsgtedjd' Global $sSession_key = 'BhKl7Ijdu4E3pzHhKu7K5fQrvzf9p3wq/diRMt7bZka7' Global $sjson_req = '{"filter":{ }}' Global $hOpen = _WinHttpOpen() ; Get Session handle ; ##### CHECKED AND VALID HANDLE IS RETURNED ##### Global $hConnect = _WinHttpConnect($hOpen, $sAddress) ; Get connection handle ; ##### CHECKED AND VALID HANDLE IS RETURNED ##### Global $hRequest = _WinHttpOpenRequest($hConnect, 'POST') ; Make a request ; ##### CHECKED AND VALID HANDLE IS RETURNED ##### ; Add header fields to the request _WinHttpAddRequestHeaders($hRequest, 'X-Application: ' & $sAppKey) _WinHttpAddRequestHeaders($hRequest, 'X-Authentication: ' & $sSession_key) _WinHttpAddRequestHeaders($hRequest, 'Accept: application/json') _WinHttpAddRequestHeaders($hRequest, 'Content-Type: application/json') _WinHttpSendRequest($sPostData, 'Data=' & $sjson_req, $hRequest) ; Send it _WinHttpReceiveResponse($hRequest) ; Wait for the response ; Check if there is a response Global $sHeader, $sReturned If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest) MsgBox(64, 'Header', $sHeader) Do $sReturned &= _WinHttpReadData($hRequest) Until @error ConsoleWrite($sReturned) ; Print returned Else ConsoleWriteError('!No data available.' & @CRLF) MsgBox(48, 'Failure', 'No data available.') ;##### <==== ALWAYS FAILS HERE! ##### EndIf ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) I am sure that I have probably missed out a vital line, but for the life of me I can't see the wood for the trees anymore. Anyone got any suggestions? Many thanks, Pete
trancexx Posted October 2, 2019 Posted October 2, 2019 (edited) Maybe like this: #include "WinHttp.au3" $sAddress = 'https://api.betfair.com/exchange/betting/json-rpc/v1/' $sAppKey = '4YpsEhdsgtedjd' $sSession_key = 'BhKl7Ijdu4E3pzHhKu7K5fQrvzf9p3wq/diRMt7bZka7' $sjson_req = '{"filter":{ }}' $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, $sAddress) $sReturned = _WinHttpSimpleSSLRequest($hConnect, "POST", "listEventTypes/", Default, $sjson_req, 'X-Application: ' & $sAppKey & @CRLF & 'X-Authentication: ' & $sSession_key & @CRLF & 'Content-Type: application/json', Default, Default, Default, Default, 1) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ConsoleWrite($sReturned & @CRLF) Edited October 2, 2019 by trancexx pete_wilde and Earthshine 1 1 ♡♡♡ . eMyvnE
pete_wilde Posted October 2, 2019 Author Posted October 2, 2019 Hi Trancexx, Many thanks for your quick response. I have actually seen your solutions posted on many queries. You are seriously knowledgable my friend. The script now returns the message: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Service not Found</title> </head> <body> <b>The URL you specified did not correspond to a service.x</b> </body> </html> Normally, it should return a JSON string which the user then decodes. It is much better than anything which I have got so far. I will have a play about with it 🙂 Many thanks for your help. Best regards, Pete
seadoggie01 Posted October 2, 2019 Posted October 2, 2019 (edited) Any reason your code needs to be in AutoIt? You could run your python script and get the results in AutoIt through the command line (since your python code already works) #include <AutoItConstants.au3> ; Start your python code Local $iPID = Run('"C:\python\path\python.exe"' & '"C:\other\path\script.py"', @SW_HIDE, $STDOUT_CHILD) ; Wait for the python code to end ProcessWaitClose($iPID) ; Read the results Local $sResults = StdoutRead($iPID) Edit: This would read everything you "print" out in your python script. Alternately, you could have your python write the results to a file Edited October 2, 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
trancexx Posted October 3, 2019 Posted October 3, 2019 4 hours ago, pete_wilde said: Hi Trancexx, Many thanks for your quick response. I have actually seen your solutions posted on many queries. You are seriously knowledgable my friend. The script now returns the message: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Service not Found</title> </head> <body> <b>The URL you specified did not correspond to a service.x</b> </body> </html> Normally, it should return a JSON string which the user then decodes. It is much better than anything which I have got so far. I will have a play about with it 🙂 Many thanks for your help. Best regards, Pete Maybe besause it shoud be like in your original code unlike your AutoIt one: "https://api.betfair.com/exchange/betting/rest/v1.0/" ♡♡♡ . eMyvnE
pete_wilde Posted October 3, 2019 Author Posted October 3, 2019 19 hours ago, trancexx said: Maybe besause it shoud be like in your original code unlike your AutoIt one: "https://api.betfair.com/exchange/betting/rest/v1.0/" Tried the alternative URL and got the same result. Might just need something else added to the URL. I will play about with it and see what happens. You have definitely got me much further than I previously was, so many thanks for that. It is much appreciated 🙂
Danyfirex Posted October 4, 2019 Posted October 4, 2019 Hello. If you want to use the JSON-RPC protocol endpoint you need to define your json correclty "method,params ,id." Otherwise you could use regular JSON REST endpoints and send just parameters. Check Doc Table: Interface Endpoint JSON-RPC Prefix <method> Example JSON-RPC https://api.betfair.com/exchange/betting/json-rpc/v1 <method> SportsAPING/v1.0/listMarketBook JSON REST https://api.betfair.com/exchange/betting/rest/v1.0/ listMarketBook/ Saludos pete_wilde 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
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