python 学习中遇到的问题整理

解决无法加载UIAutomationCore.dll的报错

PHPer 2024-09-05 12 0 0

上述错误是在打包后的软件中出现,在PyCharm的运行过程中并没有出现。

解决办法,再项目源码里引入

from comtypes.gen.UIAutomationClient import IUIAutomation

前言: 此问题是在Python开发环境下关于UIAutomation的报错问题,问题来源于生产环境中的几台WIN10系统报错。

module 'comtypes.gen.UIAutomationClient' has no attribute 'IUIAutomation'Can not load UIAutomationCore.dll.1, You may need to install Windows Update KB971513 if your OS is Windows XP, see https://github.com/yinkaisheng/WindowsUpdateKB9715...2, you need to use an UIAutomationInitializerInThread object if use uiautomation in a thread, see demos/uiautomation_in_thread.py


因为在生产环境中出现,当时是怀疑是UIAutomationCore.dll在系统中没有生效,所以尝试过如下的方法(以管理员身份执行如下cmd命令),但始终没有效果,该报错还是报错;也怀疑过WIN10上缺少KB971513的补丁,为此还特地找过对应的补丁安装,但是该补丁只适用于Windows XP系统,在安装的时候存在类似“当前系统无法安装”的提示。

>cd C:\Windows\System32
>regsvr32 UIAutomationCore.dll


由于生产环境不联外网,不好远程调试。本地开发环境又复现不出该问题,

所以当时,虽然无奈地将原因归结于未知的系统原因,但只能先弃用有报错的几台WIN10系统,换别的系统进行业务操作。

直到现在,这个问题过去了有将近半年的时间,终于在开发环境上复现了!

初步定位,是在执行control = uiautomation.ControlFromPoint()的语句时出错,于是在此处捕获异常后打印堆栈信息如下:

Traceback (most recent call last):

File "test_hook.py", line 112, in get_mouse

File "uiautomation\uiautomation.py", line 8164, in ControlFromPoint

File "uiautomation\uiautomation.py", line 52, in instance

File "uiautomation\uiautomation.py", line 71, in __init__

File "uiautomation\uiautomation.py", line 60, in __init__

AttributeError: module 'comtypes.gen.UIAutomationClient' has no attribute 'IUIAutomation'


然后根据堆栈信息找到出错位置对应的uiautomation.py源码

class _AutomationClient:

_instance = None

@classmethod

def instance(cls) -> '_AutomationClient':

"""Singleton instance (this prevents com creation on import)."""

if cls._instance is None:

cls._instance = cls()

return cls._instance

def __init__(self):

tryCount = 3

for retry in range(tryCount):

try:

self.UIAutomationCore = comtypes.client.GetModule("UIAutomationCore.dll")

self.IUIAutomation = comtypes.client.CreateObject("{ff48dba4-60ef-4201-aa87-54103eef594e}", interface=self.UIAutomationCore.IUIAutomation)

self.ViewWalker = self.IUIAutomation.RawViewWalker

#self.ViewWalker = self.IUIAutomation.ControlViewWalker

break

except Exception as ex:

if retry + 1 == tryCount:

Logger.WriteLine('''

{}

Can not load UIAutomationCore.dll.

1, You may need to install Windows Update KB971513 if your OS is Windows XP, see https://github.com/yinkaisheng/WindowsUpdateKB9715......

立即注册

更新于:2024-09-05 22:07:15
    您需要登录后才可以评论。 立即注册
    相关内容

    apache服务无法启动的解决方法

    解决编译时Could NOT find UV (missing: UV_LIBRARY UV_INCL...

    Windows10 修改 hosts 拒绝访问如何解决

    关于编程时遇到意想不到的错误如何解决

    解决新版wampserver 2/3个服务器正在运行问题

    wamp安装成功了,在cmd上运行php.exe时,提示'"php.exe"' 不是内部或外部命令

    wamp设置mysql8.0.18初始密码问题

    myslq密码也重新设置了,可是项目在连接mysql时提示失败'root'@'localhost'...

    推荐内容

    分享几个好用的bt搜索bt资源下载网址网站

    影视电影剧集动漫综艺bt资源在线播放网址网站推荐分享

    全网最新bt磁力搜索引擎bt资源bt网站网址分享

    人气美女女优百度指数排行榜(波多野结衣,苍井空,三上悠亚,深田咏美,桥本有菜,北条...

    最强人造人深田咏美,业界的社交女王

    人生起起落落的三上悠亚,成名前的清纯风,怎么搭配出来的?

    业内第一大长腿,桥本有菜的腿究竟有多长

    波多野结衣,岛国业界著作最多的超级劳模

    日本AV界NO.1,苍井空是多少宅男的疯狂?

    美女女优视频混剪 This Girl-Laza Morgan

    怎样使用V2Ray代理和SSTap玩如魔兽世界/绝地求生/LOL台服/战地3/黑色沙漠/彩...

    sstap游戏代理教程 从此玩如魔兽世界/绝地求生/LOL台服/战地3/黑色沙漠/彩虹六...

    影视电影剧集动漫综艺bt资源在线播放网址网站推荐分享