ahk_requests - HTTP Requests using Python's requests library. Easily add headers, perimeters, grab webpages or API com

Post your working scripts, libraries and tools.
sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

ahk_requests - HTTP Requests using Python's requests library. Easily add headers, perimeters, grab webpages or API com

Post by sashaatx » 04 Apr 2023, 15:57

Hi everyone,

I am excited to share my new AutoHotkey library that aims to extend the default 'download()' function without invoking WinHTTP comobj. This provides the ability to make HTTP GET requests with headers, parameters, and parsing. This library is based on Python's Requests library and is designed to simplify HTTP requests and responses in AutoHotkey.

Here are some of the key features of the library:

Simple syntax: With this library, you can make GET requests with just a single function call.
Custom headers and parameters: You can easily add custom headers and parameters to your requests.
JSON and text support: The library can automatically parse JSON responses and return them as objects or return plain text.
Error handling: The library raises exceptions for common HTTP errors, such as 404 Not Found or 500 Internal Server Error, so you can handle them gracefully in your code.

Todo:
-update params to optional
-add comprehension to python
-improve compilation

find release and details here: https://github.com/samfisherirl/ahk_requests.py

Note, these examples are subject to change. Use the github to receive updates and changes.

Code: Select all

#Include %A_ScriptDir%\lib\JXON.ahk
#Include %A_ScriptDir%\lib\ahk_requests.ahk
;grab python executable here https://github.com/samfisherirl/ahk_requests.py
;praise and credit to: https://github.com/TheArkive/JXON_ahk2

; Simple 
url := "https://httpbin.org/get"
; see bottom for additional params
req := requests(url)

req.get()

msgbox(req.jdata["origin"])
msgbox(req.txt)

/*
**************************************************************
*/

; Intermediate example

url := "https://httpbin.org/get"
headers := Map("key1", "value1")
params := Map("key1", "value1")
req := requests(url, headers, params)

req.get()

msgbox(req.jdata["origin"])
msgbox(req.txt)





/*
**************************************************************
*/
; Complex example Airtable API 
; https://github.com/josephbestjames/airtable.py

api_key := "xxxxx"
base_id := "yyyyy"
table_name := "zzzzzz"

url := "https://api.airtable.com/v0/" . base_id  . "/" . table_name
headers := Map(
            "Authorization", 
            "Bearer " . api_key
            )
; headers := False => gets converted to {"User-Agent":"Mozilla/5.0 (Macintosh;...
params := Map("view", "Grid view")
req := requests(url, headers, params)

req.allowRedirect := True ;optional
req.stream := False ;optional

req.get()
msg := ""
for k, v in req.jdata
{
    ;json data
    try {
    msg .= k . ": " . v . "`n"
    }
    catch {
        continue
    }
}
msgbox(msg)
msgbox(req.txt)

https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

GamesOfFreak
Posts: 26
Joined: 15 Sep 2020, 03:51
Location: Germany
Contact:

Re: ahk_requests - HTTP Requests using Python's requests library. Easily add headers, perimeters, grab webpages or API c

Post by GamesOfFreak » 25 May 2023, 16:01

If I tried to download release--.zip I got a Virus Message from Chrome.

burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: ahk_requests - HTTP Requests using Python's requests library. Easily add headers, perimeters, grab webpages or API c

Post by burque505 » 27 May 2023, 08:32

@sashaatx, I tried to run the example. This code is in ahkrequests.ahk, Line 38:

Code: Select all

this.py := Dir "\ahk_requests.exe"
But there's no ahk_requests.exe on Github for it, so I compiled and got a warning related to this line:

Code: Select all

137: this.jdata := Jxon_Load(&jdata
It did compile, though. Running the example didn't give any result, either running from console as admin or by double clicking.
Can I trouble you for info on how to get this running? Thanks! BTW I have Python 3.10 installed and on my path.
Regards,
burque505

sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

Re: ahk_requests - HTTP Requests using Python's requests library. Easily add headers, perimeters, grab webpages or API c

Post by sashaatx » 27 May 2023, 15:38

burque505 wrote:
27 May 2023, 08:32
@sashaatx, I tried to run the example. This code is in ahkrequests.ahk, Line 38:

Code: Select all

this.py := Dir "\ahk_requests.exe"
But there's no ahk_requests.exe on Github for it, so I compiled and got a warning related to this line:

Code: Select all

137: this.jdata := Jxon_Load(&jdata
It did compile, though. Running the example didn't give any result, either running from console as admin or by double clicking.
Can I trouble you for info on how to get this running? Thanks! BTW I have Python 3.10 installed and on my path.
Regards,
burque505
I meant to scrap this for a C# request handler, the 8mb python executable is a bit overkill. I just havent gotten around to it. Many individuals also point out the usability of comobjects and up until a couple months ago they might as well have been in latin. I dont have experience with .dll importing, or anywhere near the knowledge of people who tell me even putting this out was dumb. I would recommend using winhttp in the mean time: https://github.com/thqby/ahk2_lib/blob/master/WinHttpRequest.ahk
Last edited by sashaatx on 27 May 2023, 16:21, edited 1 time in total.
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :


Post Reply

Return to “Scripts and Functions (v2)”