spyoungtech/ahk

AHKProtocolError: Unexpected data received. This is usually the result of an unhandled error in the AHK process.

Sebastian-Nielsen opened this issue · 2 comments

AHK: v1
Python: 3.11

Why am I getting this error?

The executeable_path is correct; I know that because whenever I purposefully change it to something incorrect, it gives me another error saying that the executeable_path is incorrect.

Note that I am targeting AutoHotKey version 1 here.

My script.py

from ahk import AHK  # https://github.com/spyoungtech/ahk

ahk = AHK(executable_path='C:/Programmer/Autohotkey/AutoHotkey.exe')
print(ahk.list_windows())

If I were to target ahk v2, I would change the path to C:/Programmer/Autohotkey/v2/AutoHotkey.exe. But as you can see, I am targeting v1.

This error is not specific to ahk.list_windows() but happens with all ahk methods I attempt to call.

Traceback (most recent call last):
File "C:\Users\www\AppData\Local\Programs\Python\Python311\Lib\site-packages\ahk\_sync\transport.py", line 735, in send
lines_to_read = int(num_lines) + 1
^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\www\IdeaProjects\rel-investment-info-service\src\main\java\dk\QQQ\drb\investment\domain\country\getMouseCoords.py", line 11, in <module>
print(ahk.list_windows())
^^^^^^^^^^^^^^^^^^
File "C:\Users\www\AppData\Local\Programs\Python\Python311\Lib\site-packages\ahk\_sync\engine.py", line 600, in list_windows
resp = self._transport.function_call('AHKWindowList', args, engine=self, blocking=blocking)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\www\AppData\Local\Programs\Python\Python311\Lib\site-packages\ahk\_sync\transport.py", line 576, in function_call
return self.send(request, engine=engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\www\AppData\Local\Programs\Python\Python311\Lib\site-packages\ahk\_sync\transport.py", line 737, in send
raise AHKProtocolError(
    ahk._sync.transport.AHKProtocolError: Unexpected data received. This is usually the result of an unhandled error in the AHK process.

Process finished with exit code 1

This code works as expected, Im able to trigger the hotkey:

def my_callback():
    print('asdf')
ahk.add_hotkey('#n', callback=my_callback)
ahk.start_hotkeys()

Hmm. This might happen if the version of AHK is incompatible with the script used by the package. I'm not sure what else might cause this problem.

Can you tell me exactly which version of AutoHotkey.exe you are using? This can be obtained with the following run in a command prompt:

echo msgbox % "my ahk version: " A_AhkVersion | C:\Programmer\Autohotkey\AutoHotkey.exe /CP65001 /ErrorStdOut *

You should see the version reported in a msgbox:

image

For reference, the package is tested against AutoHotkey 1.1.33.09 (64bit unicode verion). I would expect newer versions of v1 to also work, but older versions may not. You can try using this known-working version to see if that makes any difference in your problem.

I am using AHK v1.1.09.04, so this might be the reason. I will try with a newer version
image

EDIT:

Upgrading to AHK v1.1.33.09 (64bit unicode verion) solved it