PyAutoGui 点击权限错误 [英] PyAutoGui click permissions error

查看:53
本文介绍了PyAutoGui 点击权限错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的问题,我以前在 python 中没有见过.

I have a very strange problem that I haven't seen happen in python before.

我有一个脚本可以在一台电脑上完美运行,当我尝试在另一台电脑上使用它时,我定义的函数失败了.

I have a script that works flawlessly on one pc and when I try to use it on another my defined function fails.

我正在使用 PyAutoGUI 来自动化一些过程.

I'm using PyAutoGUI to automate some processes.

import csv
import pyautogui

pyautogui.PAUSE = 0.50
pyautogui.FAILSAFE = True


#click function requires arguments ('fullPathToImage', "Error Identifier")
def click(fullPathToImage, error):
    try:
        pyautogui.click(pyautogui.center(pyautogui.locateOnScreen(fullPathToImage)))
    except:
        print(error, " not found, trying again")
        click(fullPathToImage, error)

def start():
    click('C:/projects/images/test.png', "test.png")
    pyautogui.typewrite("This is my test text")

if __name__ == '__main__':
    start()

另一台机器上发生的事情是,当它定位图像时,它在 try 语句中按预期移动鼠标并单击,但随后它也立即执行了 except 语句.

What is happening on this other machine is when it locates the image, it moves the mouse and clicks as expected in the try statement but then it immediately executes the except statement too.

我们两台机器之间的唯一区别是我运行的是枕头 3.1.1,而它无法运行的机器是运行枕头 3.3.0.

The only difference between our two machines is I'm running pillow 3.1.1 and the one it doesn't work on is running pillow 3.3.0.

我的直觉是发生了一些变化,它不会在触发异常的点击时返回成功标志.我不知道为什么会这样,因为所有枕头都用于图像识别.

My instinct is something changed that isn't returning a success flag on click which is triggering the exception. I don't know why that would be the case since all pillow is used for is image recognition.

诚然,我对错误捕获还很陌生,我不知道从哪里继续.任何帮助将不胜感激.

Admittedly I'm pretty new to error catching and I'm not sure where to continue from here. Any help would be greatly appreciated.

edit:在异常中调用click函数的原因是为了消除加载屏幕期间的wait语句.不取决于正在处理的数据量,很难对延迟进行预编程.

edit: the reason for calling the click function in the exception is to eliminate wait statements during loading screens. depending no the amount of data being processed it's difficult to preprogram delays.

推荐答案

所以事实证明这是由于这台机器上的权限错误.由于它是商用计算机,因此用户没有管理员权限.这导致点击被注册,然后立即触发 WinError 5 异常.我通过向我的 try 块添加另一个异常解决了这个问题."except PermissionError: pass" 见下实现

So it turns out this was due to a permissions error on this machine. Due to it being a business computer the user didn't have admin rights. This caused clicks to be registered and then immediately triggered a WinError 5 exception. I solved this by adding another exception to my try block. "except PermissionError: pass" See below for implementation

import csv
import pyautogui

pyautogui.PAUSE = 0.50
pyautogui.FAILSAFE = True


#click function requires arguments ('fullPathToImage', "Error Identifier")
def click(fullPathToImage, error):
    try:
        pyautogui.click(pyautogui.center(pyautogui.locateOnScreen(fullPathToImage)))
##################################    
    except PermissionError:
        pass
##################################    
    except:
        print(error, " not found, trying again")
        click(fullPathToImage, error)

def start():
    click('C:/projects/images/test.png', "test.png")
    pyautogui.typewrite("This is my test text")

if __name__ == '__main__':
    start()

这篇关于PyAutoGui 点击权限错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆