gpt4 book ai didi

Python PyAutoGUI 返回 "ImageNotFoundException",但 "except"不将其识别为异常

转载 作者:太空宇宙 更新时间:2023-11-04 04:21:16 32 4
gpt4 key购买 nike

使用以前版本的 pyautogui,当找不到图像时,返回的是“None”,所以我用 except TypeError: 来处理它。但是自更新(版本 0.9.41)以来,它无法正常工作,因为它返回 ImageNotFoundException,但未被识别为异常。当我尝试执行 except ImageNotFoundException: 时出现错误:

[E0712] Catching an exception which doesn't inherit from Exception: ImageNotFoundException

应该如何处理这个错误?

最佳答案

这适用于 pyautogui 0.9.52python 3.9.0

import pyautogui

# force use of ImageNotFoundException
pyautogui.useImageNotFoundException()

try:
location = pyautogui.locateOnScreen('foo.png')
print('image found')
except pyautogui.ImageNotFoundException:
print('ImageNotFoundException: image not found')

我在此页面中找到了 useImageNotFoundException() 部分 locateCenterOnScreen doesn't raise ImageNotFoundException. · Issue #441 · asweigart/pyautogui .如果未调用 useImageNotFoundException()locateOnScreen() 只会返回 None

关于Python PyAutoGUI 返回 "ImageNotFoundException",但 "except"不将其识别为异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54461133/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com