I have a question regarding how to use Python pywinauto package.

Asked 2 years ago, Updated 2 years ago, 24 views

Traceback (most recent call last):
  File "C:\Anaconda3\lib\ctypes\__init__.py", line 121, in WINFUNCTYPE
    return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'ctypes.c_long'>, <class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.c_long'>, <class 'comtypes.LP_POINTER(IUIAutomationTextRange)'>), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/parkk/PycharmProjects/untitled1/openapi.py", line 1, in <module>
    from pywinauto import application
  File "C:\Anaconda3\lib\site-packages\pywinauto\__init__.py", line 89, in <module>
    from . import findwindows
  File "C:\Anaconda3\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
    from . import controls
  File "C:\Anaconda3\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
    from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
  File "C:\Anaconda3\lib\site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module>
    from ..uia_defines import IUIA
  File "C:\Anaconda3\lib\site-packages\pywinauto\uia_defines.py", line 181, in <module>
    pattern_ids = _build_pattern_ids_dic()
  File "C:\Anaconda3\lib\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
    if hasattr(IUIA().ui_automation_client, cls_name):
  File "C:\Anaconda3\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__
    cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
  File "C:\Anaconda3\lib\site-packages\pywinauto\uia_defines.py", line 60, in __init__
    self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
  File "C:\Anaconda3\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "C:\Anaconda3\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper
    mod = _my_import(fullname)
  File "C:\Anaconda3\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import
    return __import__(fullname, globals(), locals(), ['DUMMY'])
  File "C:\Anaconda3\lib\site-packages\comtypes\gen\_944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py", line 2217, in <module>
    ( ['out', 'retval'], POINTER(POINTER(IUIAutomationElementArray)), 'children' )),
  File "C:\Anaconda3\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__
    self._make_methods(value)
  File "C:\Anaconda3\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods
    prototype = WINFUNCTYPE(restype, *argtypes)
  File "C:\Anaconda3\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE
    class WinFunctionType(_CFuncPtr):
TypeError: item 2 in _argtypes_ passes a union by value, which is unsupported.

Process finished with exit code 1

The above is an error that occurs when the code below is executed in Faicham.

from pywinauto import application
from pywinauto import timings
import time
import os

app = application.Application()
app.start("C:/Kiwoom/KiwoomFlash2/khministarter.exe")

title = "Lightning Login"
dlg = timings.WaitUntilPasses(20, 0.5, lambda: app.window_(title=title))

The pywinauto package was downloaded from the Windows power shell via the pip command and executed.

The Windows file you want to run is installed, and the directory is fine.

There is a suspicion that the PyCham Python console may not recognize the package, but it is wandering because it does not know how to check whether it is recognized.

I'd appreciate it if you could tell me what I'm missing or how to fix this error.

python

2022-09-21 12:40

1 Answers

Check out the Python version.

It's a registered issue and there's a problem with the latest version of Python. The latest version here is the updated version of ctypes.

It seems that the type was changed when processing COM type in ctypes, but it seems to be taken care of in the next fix version due to Python issue.

This means that if the last fix version, such as 3.8.1 or 3.7.6, is up to date, it's a problem.

Downgrading Python to 3.8.0 or 3.7.5 is no problem.

https://github.com/pywinauto/pywinauto/issues/868


2022-09-21 12:40

If you have any answers or tips


© 2025 OneMinuteCode. All rights reserved.