Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XGetImage() failed when using mss #115

Closed
mazjindeel opened this issue Mar 10, 2019 · 14 comments
Closed

XGetImage() failed when using mss #115

mazjindeel opened this issue Mar 10, 2019 · 14 comments

Comments

@mazjindeel
Copy link

mazjindeel commented Mar 10, 2019

General information:

  • OS name: _Debian GNU/Linux_Ubuntu
  • OS version: 18.10
  • OS architecture: 64 bits
  • Resolutions:
    • Monitor 1: 1920x1080
    • Monitor 2: 1920x1080
  • Python version: 3.7.1
  • MSS version: 4.0.2

For GNU/Linux users:

  • Display server protocol and version, if known: X server wayland
  • Desktop Environment: Unity
  • Composite Window Manager name and version: [not sure, it's gonna be whatever ubuntu 18.10 uses by default - I haven't configured any of this stuff]

Description of the warning/error

When I use any screen capture command (grab(), shot()), I get an error that XGetImage failed.
code:
pipenv install mss

and in file process.py, I have taken some code straight the examples in documentation:

import mss
with mss.mss() as sct:
    try:
        filename = sct.shot(mon=-1, output='fullscreen.png')
        print(filename)
    except Exception as e:
        print(e, "\n", e.details)

The above code outputs this:

XGetImage() failed
 {'retval': <mss.linux.LP_XImage object at 0x7fc72d567bf8>, 'args': (<mss.linux.LP_Display object at 0x7fc72db7d1e0>, <mss.linux.LP_Display object at 0x7fc72d567950>, 0, 0, 1920, 1080, 16777215, 2)}

And the stracktrace looks like this:

Traceback (most recent call last):
  File "process.py", line 3, in <module>
    filename = sct.shot(mon=-1, output='fullscreen.png')
  File "/home/f41lurizer/.local/share/virtualenvs/poker-TAtsjijf/lib/python3.7/site-packages/mss/base.py", line 140, in shot
    return next(self.save(**kwargs))
  File "/home/f41lurizer/.local/share/virtualenvs/poker-TAtsjijf/lib/python3.7/site-packages/mss/base.py", line 129, in save
    sct = self.grab(monitor)
  File "/home/f41lurizer/.local/share/virtualenvs/poker-TAtsjijf/lib/python3.7/site-packages/mss/linux.py", line 430, in grab
    ZPIXMAP,
  File "/home/f41lurizer/.local/share/virtualenvs/poker-TAtsjijf/lib/python3.7/site-packages/mss/linux.py", line 171, in validate
    raise ScreenShotError(err, details=details)
mss.exception.ScreenShotError: XGetImage() failed

Other details

I have also tried running as root, and running outside of tmux. Neither of these things changed the error I'm getting. I wonder if this has something to do with using wayland? On pyscreenshot, they seem to have limited support for screenshots on wayland.

@BoboTiG
Copy link
Owner

BoboTiG commented Mar 10, 2019

Did it worked with an older version of MSS?
I have the same setup and it works well, can you tell me if there is something than can help me reproduce?

I tried onetime a distribution using Wayland and it worked well too 🤔

@BoboTiG
Copy link
Owner

BoboTiG commented Mar 10, 2019

Could you try the current version from the master branch and also add this line print(sct.xlib) and tell me what is the output?

@mazjindeel
Copy link
Author

mazjindeel commented Mar 10, 2019

I don't know if it worked with an older version of MSS, this is my first time using the library.

running it with latest version from master, here is the output of print(sct.xlib)
<CDLL 'libX11.so.6', handle 5558e685ac30 at 0x7ff154199588>

Interestingly the traceback is a bit diferent now:

Traceback (most recent call last):
  File "mss_example.py", line 5, in <module>
    filename = sct.shot(mon=-1, output='fullscreen.png')
  File "/home/maz/.local/share/virtualenvs/mss-a6085d73/lib/python3.7/site-packages/mss/base.py", line 149, in shot
    return next(self.save(**kwargs))
  File "/home/maz/.local/share/virtualenvs/mss-a6085d73/lib/python3.7/site-packages/mss/base.py", line 137, in save
    sct = self.grab(monitor)
  File "/home/maz/.local/share/virtualenvs/mss-a6085d73/lib/python3.7/site-packages/mss/linux.py", line 427, in grab
    ZPIXMAP,
  File "/home/maz/.local/share/virtualenvs/mss-a6085d73/lib/python3.7/site-packages/mss/linux.py", line 175, in validate
    raise ScreenShotError(err, details=details)
mss.exception.ScreenShotError: XGetImage() failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "mss_example.py", line 6, in <module>
    print(filename)
  File "/home/maz/.local/share/virtualenvs/mss-a6085d73/lib/python3.7/site-packages/mss/base.py", line 38, in __exit__
    self.close()
  File "/home/maz/.local/share/virtualenvs/mss-a6085d73/lib/python3.7/site-packages/mss/linux.py", line 337, in close
    self.xlib.XCloseDisplay(self.display)
  File "/home/maz/.local/share/virtualenvs/mss-a6085d73/lib/python3.7/site-packages/mss/linux.py", line 175, in validate
    raise ScreenShotError(err, details=details)
mss.exception.ScreenShotError: XCloseDisplay() failed

@BoboTiG
Copy link
Owner

BoboTiG commented Mar 10, 2019

The new stack trace is OK actually, I will fix it later. But the issue remains.

I will have to download the same Ubuntu version as yours to test, could you point me to the ISO you used?

@mazjindeel
Copy link
Author

Hi, here is a link to the ISO. It's the default Ubuntu 18.10 64-bit download.
https://www.ubuntu.com/download/desktop/thank-you/?version=18.10&architecture=amd64

@BoboTiG
Copy link
Owner

BoboTiG commented Mar 16, 2019

So I downloaded the same ISO, and I cannot reproduce.
I have this screenshot when copy-pasting the same code as in the issue description
fullscreen

And using a simple python3 -m mss works like a charm too:
monitor-1

@mazjindeel
Copy link
Author

Thanks for taking the time to try and reproduce this. I guess it must be configuration issue I'm having locally, I'll have to just run this in a VM. Thanks for all the help, sorry to waste your time!

@BoboTiG
Copy link
Owner

BoboTiG commented Mar 16, 2019 via email

@thuraiselvaraj
Copy link

The Error Is Due to the Wrong Resolution.Just reduce the resolution and try Again (Keep it In the range(700,400)

@nubonics
Copy link

nubonics commented May 1, 2020

Another way to reproduce this error is to use another display besides :1 in linux
suchas export DISPLAY=:2 (with a vncserver running on this display)

CORRECTION: giving the size of a window larger than the vncserver has set as its geometry will result in this error, however, works fine when you specify the correct geometry :D

@mike546378
Copy link

So just ran into this issue myself. Have 4 monitors; 3x1080p and 1x1440p. Trying to capture the 1440p monitor, however, as soon as the width or height is set >= 1407 I get this error.
If I disable all the 1080p monitors then I am able to capture the full 2560x1440 area without issue, with the 1080p monitors enabled though the maximum area I have been able to capture so far is 1406x1406.
Will update if I find any workarounds

@pertinency
Copy link

Another way to reproduce this error is to use another display besides :1 in linux
suchas export DISPLAY=:2 (with a vncserver running on this display)

CORRECTION: giving the size of a window larger than the vncserver has set as its geometry will result in this error, however, works fine when you specify the correct geometry :D

I just have solve this issue with this reply.
I'm using vnc server and I don't know why resolution of my display is set by 1900x1200 rather than 1920x1080.
The way how I found my resolution of display is followed by this method.
After that, sct.grab({"top": 0, "left": 0, "width": 1900, "height": 1200}) has works correctly to me.

Thanks a lot!!

@will-afs
Copy link

will-afs commented Jan 31, 2023

Hey all, thanks for developing this library.

I am getting the same issue as described in this thread though.
I'm working under Ubuntu 22.04, with a resolution of 1920x1080 (16:9) on both of my screens. Couldn't set it to lower than 800 x 600. Anyway, having a such low resolution is uncomfortable to work so I don't really understand the point of requiring lowering it that much?

Anyway, can this library be considered as usable for projects in which the screen resolution is unpredictable (given a variety of users)?

@BoboTiG
Copy link
Owner

BoboTiG commented Jan 31, 2023

Anyway, can this library be considered as usable for projects in which the screen resolution is unpredictable (given a variety of users)?

Of course, that's the primary use case of the project. Have a look, it's used in hundreds of other projects.
Here, it's a specific error due to either Wayland, or VNC. And tweaking the VNC configuration seems to have worked.

Repository owner locked as too heated and limited conversation to collaborators Jan 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants