Error trying to download the V1 and V2 files with current version number

Report problems with documented functionality
User avatar
joedf
Posts: 9000
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by joedf » 13 May 2024, 09:40

I feel that... 99% of my stuff is still v1.1 :P
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

User avatar
lmstearn
Posts: 698
Joined: 11 Aug 2016, 02:32
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by lmstearn » 13 May 2024, 10:01

All the files e.g this one won't work with URLDownloadToFile.
https://www.autohotkey.com/assets/images/ahk_wallpaper_reduced.jpg
Think it's related to this issue with the challenge pages from Cloudflare, one way around it might be a different user agent.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

User avatar
tank
Posts: 3130
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by tank » 22 May 2024, 09:50

I havent forgotten this. I even tried with the autohotkey user agent in postman and it worked fine. For the life of me I cannot tell what it is. unless this is something much lower level like how AHK actually impliments under the hood that is now being subverted by OS. but thats pretty difficult to accept.
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter

User avatar
joedf
Posts: 9000
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by joedf » 22 May 2024, 13:44

@lexikos Any ideas? We're not sure if it's the server configs or if it's AHK... :think:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

User avatar
JoeWinograd
Posts: 2214
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Error trying to download the V1 and V2 files with current version number

Post by JoeWinograd » 22 May 2024, 18:38

Hi @tank and @joedf,
Thanks for your continuing efforts on this...much appreciated! Hopefully, @lexikos can provide some ideas to help resolve the problem. Regards, Joe

lexikos
Posts: 9694
Joined: 30 Sep 2013, 04:07
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by lexikos » 23 May 2024, 22:46

What would I know? Download just uses a few Internet functions from wininet, as anyone can see.

Descolada
Posts: 1204
Joined: 23 Dec 2021, 02:30

Re: Error trying to download the V1 and V2 files with current version number

Post by Descolada » 26 May 2024, 09:13

This problem affects the download prompt caused by #Requires AutoHotkey ... as well, which fails with error "Download failed."

The failure is caused by InternetOpenUrl which fails with error ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, so it appears there is some kind of problem with the certificate.
Downloading via a GET request with Msxml2.XMLHTTP doesn't seem to be affected.

TAC109
Posts: 1129
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Error trying to download the V1 and V2 files with current version number

Post by TAC109 » 26 May 2024, 16:52

TAC109 wrote:
01 May 2024, 00:51
I’m also having problems using UrlDownloadToFile on https://www.autohotkey.com/mpress/mpress.219.zip, used in the Ahk2Exe Updater.
I’ve since made changes to the Ahk2Exe Updater to avoid this problem. Mpress is now downloaded from GitHub.

Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe

User avatar
JoeWinograd
Posts: 2214
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Error trying to download the V1 and V2 files with current version number

Post by JoeWinograd » 26 May 2024, 18:46

Descolada wrote:Downloading via a GET request with Msxml2.XMLHTTP doesn't seem to be affected.
Hi Descolada,
Could you post a V1 and/or V2 code snippet with that method? Thanks much, Joe

Descolada
Posts: 1204
Joined: 23 Dec 2021, 02:30

Re: Error trying to download the V1 and V2 files with current version number

Post by Descolada » 26 May 2024, 23:13

@JoeWinograd
If you only need the version number without downloading a file:

Code: Select all

req := ComObject("Msxml2.XMLHTTP")
req.open("GET", "https://www.autohotkey.com/download/2.0/version.txt", 0)
req.send()

if req.status == 200
  MsgBox "AHK 2.0 version: " req.responseText
else
  MsgBox "Failed to get AHK version"
Download to file (variant 1):

Code: Select all

DownloadURL("https://www.autohotkey.com/download/2.1/AutoHotkey_2.1-alpha.12_setup.exe")
ExitApp

DownloadURL(url, filename?) {
    local oStream, req := ComObject("Msxml2.XMLHTTP")
    req.open("GET", url, true)
    req.send()
    while req.readyState != 4
        Sleep 100

    if req.status == 200 {
        oStream := ComObject("ADODB.Stream")
        oStream.Open()
        oStream.Type := 1
        oStream.Write(req.responseBody)
        oStream.SaveToFile(filename ?? StrSplit(url, "/")[-1], 2)
        oStream.Close()
    } else
        throw Error("Download failed",, url)
}
Download to file (variant 2):

Code: Select all

DownloadURL("https://www.autohotkey.com/download/2.1/AutoHotkey_2.1-alpha.12_setup.exe")
ExitApp

DownloadURL(url, filename?) {
    local f, req := ComObject("Msxml2.XMLHTTP")
    req.open("GET", url, true)
    req.send()
    while req.readyState != 4
        Sleep 100

    if req.status == 200 {
        f := FileOpen(filename ?? StrSplit(url, "/")[-1], "w")
        f.RawWrite(NumGet(req.responseBody.ptr + 8 + A_PtrSize, "ptr"), req.responseBody.MaxIndex()+1)
        f.Close()
    } else
        throw Error("Download failed",, url)
}
EDIT: improved variant 2 speed.

lexikos
Posts: 9694
Joined: 30 Sep 2013, 04:07
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by lexikos » 27 May 2024, 03:07

Descolada wrote:
26 May 2024, 09:13
The failure is caused by InternetOpenUrl which fails with error ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, so it appears there is some kind of problem with the certificate.
That error means "The server is requesting client authentication." as in "give me a certificate that proves your identity". Apparently, if the server does not require authentication but requests it, you must send the request again with the same handles to "authenticate" anonymously.


Descolada
Posts: 1204
Joined: 23 Dec 2021, 02:30

Re: Error trying to download the V1 and V2 files with current version number

Post by Descolada » 27 May 2024, 10:54

@lexikos can confirm, changing script_autoit.cpp from

Code: Select all

	// Open the required URL
	HINTERNET hFile = InternetOpenUrl(hInet, aURL, NULL, 0, flags_for_open_url, 0);
	if (!hFile)
	{
		DWORD last_error = GetLastError(); // Save this before calling InternetCloseHandle, otherwise it is set to 0.
		InternetCloseHandle(hInet);
		return FR_E_WIN32(last_error);
	}
to

Code: Select all

	// Open the required URL
	HINTERNET hFile = InternetOpenUrl(hInet, aURL, NULL, 0, flags_for_open_url, 0);
	if (!hFile)
	{
		hFile = InternetOpenUrl(hInet, aURL, NULL, 0, flags_for_open_url, 0);
		if (!hFile)
		{
			DWORD last_error = GetLastError(); // Save this before calling InternetCloseHandle, otherwise it is set to 0.
			InternetCloseHandle(hInet);
			return FR_E_WIN32(last_error);
		}
	}
fixes the issue.

User avatar
joedf
Posts: 9000
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by joedf » 27 May 2024, 14:14

Thanks for figuring this out @Descolada :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

User avatar
JoeWinograd
Posts: 2214
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Error trying to download the V1 and V2 files with current version number

Post by JoeWinograd » 27 May 2024, 20:33

Hi @Descolada,
I can't speak to your fix of changing script_autoit.cpp, but I can say that your three scripts (version number without downloading a file, download variant 1, download variant 2) all work perfectly! Thank you very much for writing and posting them...I really appreciate it! Regards, Joe

lexikos
Posts: 9694
Joined: 30 Sep 2013, 04:07
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by lexikos » 28 May 2024, 16:48

@Descolada When I tested yesterday, both the first and second call returned error 12044. Today it works.

lexikos
Posts: 9694
Joined: 30 Sep 2013, 04:07
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by lexikos » 30 May 2024, 21:20

v2.0.16 implements the workaround for ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED.

User avatar
joedf
Posts: 9000
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Error trying to download the V1 and V2 files with current version number

Post by joedf » 31 May 2024, 07:44

lexikos wrote:
30 May 2024, 21:20
v2.0.16 implements the workaround for ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED.
:thumbup: :thumbup: :thumbup:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

Descolada
Posts: 1204
Joined: 23 Dec 2021, 02:30

Re: Error trying to download the V1 and V2 files with current version number

Post by Descolada » 05 Jun 2024, 08:54

lexikos wrote:
28 May 2024, 16:48
@Descolada When I tested yesterday, both the first and second call returned error 12044. Today it works.
Now it doesn't work again, fails with error 12044. Weird...

EDIT: and it started working again. It failed in 2.0.16, then I installed 2.1-alpha.13 and it suddenly started working. I uninstalled 2.1-alpha.13 and went back to 2.0.16, it continued working (even after rebooting). I'm guessing there is some kind of issue remaining, but I have no clue what may be causing it.

Post Reply

Return to “Bug Reports”