Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyAutoGui单击权限错误_Python_Windows_Pyautogui - Fatal编程技术网

Python PyAutoGui单击权限错误

Python PyAutoGui单击权限错误,python,windows,pyautogui,Python,Windows,Pyautogui,我有一个非常奇怪的问题,我以前从未在python中看到过 我有一个脚本,它在一台电脑上完美地工作,当我试图在另一台电脑上使用它时,我定义的函数失败了 我正在使用PyAutoGUI自动化一些过程 import csv import pyautogui pyautogui.PAUSE = 0.50 pyautogui.FAILSAFE = True #click function requires arguments ('fullPathToImage', "Error Identifier"

我有一个非常奇怪的问题,我以前从未在python中看到过

我有一个脚本,它在一台电脑上完美地工作,当我试图在另一台电脑上使用它时,我定义的函数失败了

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

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语句

我们两台机器之间的唯一区别是我运行的是pillow 3.1.1,而它不工作的机器运行的是pillow 3.3.0

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

诚然,我对错误捕捉还很陌生,我不确定从这里继续下去。任何帮助都将不胜感激


编辑:在异常中调用click函数的原因是为了消除加载屏幕期间的等待语句。根据正在处理的数据量,很难预编程延迟。

因此,这是由于这台机器上的权限错误造成的。由于它是一台商用计算机,用户没有管理员权限。这导致注册点击,然后立即触发WinError 5异常。我通过向try块添加另一个异常来解决这个问题。“除PermissionError:pass外”的实现见下文

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()

自版本0.9.34起,此问题已得到修复。(或者至少已经解决了。点击看起来确实有效,但现在PyAutoGUI抑制了这个异常。)您所要做的就是使用
pip安装-U PyAutoGUI从PyPI安装或更新PyAutoGUI