Pywinauto: _ctypes.COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None) )

Created on 26 Jan 2017  路  20Comments  路  Source: pywinauto/pywinauto

Hi,

Is some situations i get this COMError. Any ideas?

Code i'm running

import pywinauto

def click_button(button):
    app = pywinauto.Application(backend='uia')
    appconnect = app.connect(path='software.exe')
    window = appconnect.window()
    window.set_focus()
    button = window.child_window(auto_id=button)
    wrapper = button.wrapper_object()
    wrapper.click_input()

click_button('ButtonName')

Error message:

Traceback (most recent call last):
  File "click_button.py", line 14, in <module>
    click_button('ButtonName')
  File "click_button.py", line 10, in click_button
    wrapper = button.wrapper_object()
  File "build\bdist.win-amd64\egg\pywinauto\application.py", line 249, in wrappe
r_object
  File "build\bdist.win-amd64\egg\pywinauto\application.py", line 239, in __reso
lve_control
  File "build\bdist.win-amd64\egg\pywinauto\timings.py", line 402, in wait_until
_passes
  File "build\bdist.win-amd64\egg\pywinauto\application.py", line 202, in __get_
ctrl
  File "build\bdist.win-amd64\egg\pywinauto\findwindows.py", line 84, in find_el
ement
  File "build\bdist.win-amd64\egg\pywinauto\findwindows.py", line 208, in find_e
lements
  File "build\bdist.win-amd64\egg\pywinauto\uia_element_info.py", line 270, in d
escendants
  File "build\bdist.win-amd64\egg\pywinauto\uia_element_info.py", line 249, in _
get_elements
_ctypes.COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None)
)

Priority-Critical bug

Most helpful comment

Yes. Issue is still present with 0.6.3

ptrs_array = self._element.FindAll(tree_scope, cond)

COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None))

The issue is specifically observed for 'UIA' backend and when we try to access the elements from new thread.

Operating System - Windows7x86 and 64 bit.
Same issue is not seen in Windows8.1 and Windows 10 RS1 and RS2

All 20 comments

Hmm... Never seen this in descendants() method. Looks like a bug in comtypes or even UIAutomationCore.dll. It's better to have this issue reproducible on some free downloadable application to debug it and maybe to workaround. Sorry, can't promise to include the fix into 0.6.1 (will publish soon).

I also encounter this issue when selecting a listview item:

Traceback (most recent call last):
  File "mycode.py", line 227, in define_tool
    dlg_license.ListBox.AllRoundRuntime.select()
  File "C:\Python27\lib\site-packages\pywinauto\controls\uiawrapper.py", line 511, in select self.iface_selection_item.Select()
COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None))

Hi @mwsluis if you repeat this action 2 times in a loop with try-except, is that working second time?

I'm using a custom function that just executes the function x times and if it still doesn't work throws an exception. This seems to solve the issue for now, I'll have to monitor and see if it happens again. FYI the error only occurred when the machine on which the automation ran was locked.

FYI the error only occurred when the machine on which the automation ran was locked.

Ah, this might be important! I'll try to reproduce it on my side with method .select().
Is it a WPF application? Or Qt? Or somewhat else?

It uses .net so probably wpf.

It seems I could reproduce similar problem for WireShark application. Just leaving the traceback here:

Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
    exec codeObject in __main__.__dict__
  File ".\test_wireshark.py", line 135, in <module>
    generateDataFile(t_interval,interface_name,file_name)
  File ".\test_wireshark.py", line 30, in generateDataFile
    win.window(best_match="Stop").wrapper_object().click()
  File ".\pywinauto\application.py", line 252, in wrapper_object
    ctrls = self.__resolve_control(self.criteria)
  File ".\pywinauto\application.py", line 243, in __resolve_control
    criteria)
  File ".\pywinauto\timings.py", line 402, in wait_until_passes
    func_val = func(*args)
  File ".\pywinauto\application.py", line 207, in __get_ctrl
    ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
  File ".\pywinauto\findwindows.py", line 84, in find_element
    elements = find_elements(**kwargs)
  File ".\pywinauto\findwindows.py", line 208, in find_elements
    cache_enable=True)
  File ".\pywinauto\uia_element_info.py", line 270, in descendants
    return self._get_elements(IUIA().tree_scope["descendants"], cond, cache_enable)
  File ".\pywinauto\uia_element_info.py", line 250, in _get_elements
    return elements_from_uia_array(ptrs_array, cache_enable)
  File ".\pywinauto\uia_element_info.py", line 47, in elements_from_uia_array
    return [UIAElementInfo(ptrs.GetElement(n), cache_enable) for n in range(ptrs.Length)]
ValueError: NULL COM pointer access

For me this is 100% reproducible:
File ".\pywinauto\uia_element_info.py", line 63, in __init__ self._element = IUIA().iuia.ElementFromHandle(handle_or_elem) _ctypes.COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None)

This happens always when I call UIAElementInfo(handle) with the handle being the handle from the Word 2010 Save-close dialog on Windows 7 (the dialog that pops up if you want to close Word with unsaved changes). The machine does not need to be locked for this to happen. On Windows 10 the same code works fine.

Hi @dominic1p can you try the same with 0.6.3?
@mwsluis @nimuston how about your issues with this new release?

Yes. Issue is still present with 0.6.3

ptrs_array = self._element.FindAll(tree_scope, cond)

COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None))

The issue is specifically observed for 'UIA' backend and when we try to access the elements from new thread.

Operating System - Windows7x86 and 64 bit.
Same issue is not seen in Windows8.1 and Windows 10 RS1 and RS2

Having the same issue on the windows 10
pywinauto == 0.6.3

app.top_window().print_control_identifiers() - which prints first component and then crash, but if I put the same fragment in try except block, then second call do the job without errors

failure = True
while failure
    try:
        app.top_window().print_control_identifiers()
        failure = False
    except:
        print("-----FAILURE-----")
        failure = True

Upgraded our test machine to 0.6.3 and removed my workaround code. It seems to be running well. Can;t say for sure if the issue is solved though as it happened quite randomly. If it runs for a week or 2 without errors I'll be content :)

It didn't :(

COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None))

Traceback (most recent call last):   
  [...]   
  File "MyLibrary.py", line 294, in _select_inq_license
    dlg_license.TopPanel.ListBox.child_window(title=license_name, control_type="ListItem").select()   
  File "build\bdist.win32\egg\pywinauto\controls\uiawrapper.py", line 535, in select
    self.iface_selection_item.Select()

Hi @mwsluis, thanks for the attempt.

One more report on StackOverflow about similar issue.

I experienced the same issue..
Can anyone help me please..
File "pmca\usb\driver\windows\wpd.py", line 130, in _send
_ctypes.COMError: (-2147024865, 'A device attached to the system is not functioning.', (None, None, None, 0, None))

I am trying to install openmemories:tweak for my sony alpha and this happens all the time

Hi @smtb1234 sorry for delayed reply and thanks for the report! This message A device attached to the system is not functioning looks slightly different from NULL COM pointer access. More detailed steps to reproduce or full traceback would be very helpful.

Assume you're trying to automate an application that connects to Android phone to take some actions. there. But this app is running on Windows desktop, right?

0.6.4 is out. It should fix NULL COM pointer access. For other problems please open separate issues. Closing.

hi,

i am using pywinauto 0.6.4 , i get the COMError !!!

    app = pywinauto.Application(backend="uia")
    app.start("C:\Tecnai\Exe\Service\PPHSControl.exe")
    window = app.window_(title=u'PPHSControl')
    window.wait('ready', timeout=5)
    # window.print_control_identifiers()
    button = window.child_window(title="Ramping settings...")

    button.click()

above is the code , the error pops when the button.click() is called

Traceback (most recent call last):
  File "C:/Projects/TestAutomation/TBricks/Interface/UI/TBrickUIApp.py", line 132, in <module>
    button.click()
  File "C:\Python27\lib\site-packages\pywinauto\controls\uia_controls.py", line 116, in click
    self.invoke()
  File "C:\Python27\lib\site-packages\pywinauto\controls\uiawrapper.py", line 496, in invoke
    self.iface_invoke.Invoke()
_ctypes.COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None))

Hi @bkk003 this is InvokePattern implementation error on app side or might be issue with 64-bit/32-bit app and Python mismatch (though with very low probability). Use .click_input() which is more realistic user click with moving real mouse cursor.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nixgnef picture nixgnef  路  15Comments

rajarameshmamidi picture rajarameshmamidi  路  14Comments

taiqixp picture taiqixp  路  13Comments

sglebs picture sglebs  路  22Comments

Enteleform picture Enteleform  路  19Comments