不理解错误读取不正确的权限 [英] Don't understand error reading improper permissions
问题描述
我正在尝试使用 pyautogui 为游戏制作机器人,但是当这行代码运行时:
I'm trying to make a bot for a game using pyautogui, however when this line of code runs:
if py.locateOnScreen(r"C:\Users\molta\Documents\Pythons\Poison.png")!=None:
它返回此错误:
OSError: Failed to read C:\Users\molta\Documents\Pythons\Poison.png because file is missing, has improper permissions, or is an unsupported or invalid format
阅读此错误时,我检查了正确文件类型和文件路径正确的图片,此外,我还检查了 png 是 pyautogui 库支持的文件类型.因此,我能看到的唯一问题是它的权限不正确.因此,我的问题是,如果是这样,我如何纠正它,或者我如何自己检查这一点
Reading this error I checked that the pictures where both the right file type and that the file path was correct, on top of that I also checked that png is a supported file type for the pyautogui library. Therefore the only problem I can see is that it has improper permissions. My question is therefore if it is so and how I correct it then or how I could check this myself
感谢所有指点!
如果有帮助,这是我的完整代码,然后是完整的错误
import pyautogui as py
import winsound
from time import sleep as sl
Hello=[]
turn=0
while True:
if py.locateOnScreen(r"C:\Users\molta\Documents\Pythons\Poison.png")!=None:
if turn==0:
pyautogui.typewrite(["a","f","s"], interval=0.4)
elif turn==1:
pyautogui.typewrite(["a","e"], interval=0.4)
elif turn==2:
pyautogui.typewrite(["a","a","s"], interval=0.4)
elif turn==3:
pyautogui.typewrite(["d"], interval=0.4)
sl(1)
turn+=1
if turn==5:
pyautogui.typewrite(["a","d"], interval=0.4)
turn=0
elif py.locateOnScreen(r"C:\Users\molta\Documents\Pythons\sidekick1.png")!=None:
pyautogui.typewrite(["d"], interval=0.4)
sl(1)
elif py.locateOnScreen(r"C:\Users\molta\Documents\Pythons\sidekick2.png")!=None:
pyautogui.typewrite(["d"], interval=0.4)
sl(1)
else:
sl(1)
Hello = py.locateAllOnScreen(r"C:\Users\molta\Documents\Pythons\HP.png")
if len(Hello)==2:
break
Hello=[]
if py.locateOnScreen(r"C:\Users\molta\Documents\Pythons\onwards.png")!=None:
x,y=py.locateOnScreen(r"C:\Users\molta\Documents\Pythons\onwards.png")
py.click(x, y)
sleep(1)
elif py.locateOnScreen(r"C:\Users\molta\Documents\Pythons\Check.png")!=None:
winsound.Beep(1000, 100) # Beep at 1000 Hz for 100 ms
py.alert(text="Clear the captcha",title="__Alert__", button="Done")
Traceback (most recent call last):
File "C:/Users/molta/Documents/Pythons/coliseum bot'.py", line 7, in <module>
if py.locateOnScreen(r"C:\Users\molta\Documents\Pythons\Poison.png")!=None:
File "C:\Users\molta\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 300, in locateOnScreen
retVal = locate(image, screenshotIm, **kwargs)
File "C:\Users\molta\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 281, in locate
points = tuple(locateAll(needleImage, haystackImage, **kwargs))
File "C:\Users\molta\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 146, in _locateAll_opencv
needleImage = _load_cv2(needleImage, grayscale)
File "C:\Users\molta\AppData\Local\Programs\Python\Python37\lib\site-packages\pyscreeze\__init__.py", line 113, in _load_cv2
"unsupported or invalid format" % img)
OSError: Failed to read C:\Users\molta\Documents\Pythons\Poison.png because file is missing, has improper permissions, or is an unsupported or invalid format
推荐答案
刚刚遇到了同样的问题,我找到了一个对我有用的解决方案.我所做的是:
Just had the same problem mate and I found a solution that worked for me. What I did was:
import cv2
img = cv2.imread(r"path")
y = pyautogui.locateOnScreen(img)
print(y)
这篇关于不理解错误读取不正确的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!