# A error I cannot solve

**URL:** <https://discuss.python.org/t/a-error-i-cannot-solve/40325>\
**Category:** Python Help\
**Created:** [December 5, 2023, 3:51am UTC](https://discuss.python.org/t/a-error-i-cannot-solve/40325 "2023-12-05T03:51:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antops12](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@Antops12](https://discuss.python.org/u/Antops12)\
**Post date:** [December 5, 2023, 3:51am UTC](https://discuss.python.org/t/a-error-i-cannot-solve/40325/1 "2023-12-05T03:51:53Z")

</div>

I was getting an error and couldn’t find anything on it  
code is from [https://github.com/KianBrose/Image-Recognition-Botting-Tutorial/blob/master/stickman.py](https://github.com/KianBrose/Image-Recognition-Botting-Tutorial/blob/master/stickman.py)

```auto
#This script locates the image stickman.png in the region we give it and tell you if it can see it

from pyautogui import * 
import pyautogui 
import time 
import keyboard 
import random
import win32api, win32con

while 1:
    if pyautogui.locateOnScreen('hope.png', region=(150,175,350,600), grayscale=True, confidence=0.8) != None:
        print("I can see it")
        time.sleep(0.5)
    else:
        print("I am unable to see it")
        time.sleep(0.5)

```

after running module i’m given this error

```auto
Traceback (most recent call last):
  File "R:\hhhh\i wish.py", line 11, in <module>
    if pyautogui.locateOnScreen('hope.png', region=(150,175,350,600), grayscale=True, confidence=0.8) != None:
  File "C:\Users\polan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\ __init__.py", line 172, in wrapper
    return wrappedFunction(*args, **kwargs)
  File "C:\Users\polan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\ __init__.py", line 210, in locateOnScreen
    return pyscreeze.locateOnScreen(*args, **kwargs)
  File "C:\Users\polan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\ __init__.py", line 405, in locateOnScreen
    retVal = locate(image, screenshotIm, **kwargs)
  File "C:\Users\polan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\ __init__.py", line 383, in locate
    points = tuple(locateAll(needleImage, haystackImage, **kwargs))
  File "C:\Users\polan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\ __init__.py", line 241, in _locateAll_opencv
    raise ValueError('needle dimension(s) exceed the haystack image or region dimensions')
ValueError: needle dimension(s) exceed the haystack image or region dimensions

```

I am not at all experienced

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [December 5, 2023, 6:36am UTC](https://discuss.python.org/t/a-error-i-cannot-solve/40325/2 "2023-12-05T06:36:09Z")

</div>

Exactly as it says. PyAutoGUI is refusing to try to locate `hope.png` on the screen within the region `(150,175,350,600)`, because that image _could not possibly fit_ inside that region (it is either too tall, or too wide, or both).

The “needle” and “haystack” terminology in the error message comes from the [English idiom](https://dictionary.cambridge.org/dictionary/english/needle-in-a-haystack).

Where the code says `(150,175,350,600)`, make sure that this means what you expect it to mean, by checking the documentation. For example, perhaps you expected the 350 and 600 to mean a height and width, but they actually mean right-most X and bottom-most Y. Also check the image; maybe it’s bigger than you expected.

Another way to find information is to [copy and paste the last line of the error into a search engine](https://duckduckgo.com/?q=ValueError%3A+needle+dimension(s)+exceed+the+haystack+image+or+region+dimensions). When I try this, I immediately see a few results that look helpful, such as:

> <https://stackoverflow.com/questions/66792972/is-possible-to-locateonscreen-with-specific-region>

[https://www.reddit.com/r/learnpython/comments/vsdeav/](https://www.reddit.com/r/learnpython/comments/vsdeav/)

---

<div class="post-metadata">

**Author:** ![Antops12](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@Antops12](https://discuss.python.org/u/Antops12)\
**Post date:** [December 5, 2023, 12:17pm UTC](https://discuss.python.org/t/a-error-i-cannot-solve/40325/3 "2023-12-05T12:17:32Z")

</div>

I still cannot find what is causing this issue  
I’ve used this script to confirm the size of my screen

```import

im1 = pyautogui.screenshot(region=(0,0,1920,1080))
im1.save(r"./savedimage.png")

```

then added the proper cords

```auto
if pyautogui.locateOnScreen('hope.png', region=(0,0,1920,1080), grayscale=True, confidence=0.8) != None:

```

Yet the error returned is the same

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [December 5, 2023, 8:13pm UTC](https://discuss.python.org/t/a-error-i-cannot-solve/40325/4 "2023-12-05T20:13:40Z")

</div>

What happens when you try using an image editor to open the `hope.png` file and tell you the size of the image?

---

<div class="post-metadata">

**Author:** ![da-dada](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@da-dada](https://discuss.python.org/u/da-dada)\
**Post date:** [December 5, 2023, 8:41pm UTC](https://discuss.python.org/t/a-error-i-cannot-solve/40325/5 "2023-12-05T20:41:35Z")

</div>

> [@Antops12](#):
>
> I’ve used this script to confirm the size of my screen

```auto
>>> import pyautogui

>>> screenWidth, screenHeight = pyautogui.size() # Get the size of the primary monitor.
>>> screenWidth, screenHeight
(2560, 1440)

```

---

<div class="post-metadata">

**Author:** ![Antops12](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@Antops12](https://discuss.python.org/u/Antops12)\
**Post date:** [December 5, 2023, 9:58pm UTC](https://discuss.python.org/t/a-error-i-cannot-solve/40325/6 "2023-12-05T21:58:19Z")

</div>

Thank you, the image was too big and I had not realized

Now i have encounter another problem  
when the image is nolonger in view it gives an error and stops looping

I have found a work around, Thank you for the help
