2

I'm encountering an error when using mss, on Ubuntu 18.10 (if that matters). Here's my code (Taken from their examples in the documentation, plus some extra error output):

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)

Here's the output I see when I run the code using python 3.7.

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

If it helps, here is the output if I don't catch the exception (stacktrace)

Traceback (most recent call last):
  File "process.py", line 3, in <module>
    filename = sct.shot(mon=-1, output='fullscreen.png')
  File "/home/user/.local/share/virtualenvs/poker-TAtsjijf/lib/python3.7/site-packages/mss/base.py", line 140, in shot
    return next(self.save(**kwargs))
  File "/home/user/.local/share/virtualenvs/poker-TAtsjijf/lib/python3.7/site-packages/mss/base.py", line 129, in save
    sct = self.grab(monitor)
  File "/home/user/.local/share/virtualenvs/poker-TAtsjijf/lib/python3.7/site-packages/mss/linux.py", line 430, in grab
    ZPIXMAP,
  File "/home/user/.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

I am running it in a virtual environment, in which my Pipfile.lock reports mss version 4.0.2.

I have tried running it as root, but that gave the same output. I was unable to find a similar issue in Google. I also tried running it outside of tmux, which also had no result.

DoYouEvenCodeBro
  • 391
  • 3
  • 14
  • Please extract a [mcve]. Also, since you claim to just run examples, it would be useful if you also checked the upstream bug tracker for reports of similar problems. – Ulrich Eckhardt Mar 10 '19 at 09:33
  • @UlrichEckhardt What about this makes it not minimal/complete/verifiable? I took this example from their documentation, yes, but it's a minimal example compared to my hundreds of lines of codebase. I *think* the example is minimal and verifiable, since when I run it I do encounter the same error. What is the issue here? – DoYouEvenCodeBro Mar 10 '19 at 15:57
  • @UlrichEckhardt Also, I did check bug trackers (as mentioned in the post when I said I googled). This is the only seemingly relevant result I found https://github.com/BoboTiG/python-mss/issues/105 and the issue was closed due to lack of details. – DoYouEvenCodeBro Mar 10 '19 at 15:57
  • You fixed the 'C' part of MCVE yourself. Call me picky, but if you didn't verify that this is minimal and complete (you would have found the missing `import`), I'll point out that it's not a MCVE and not bother any further. Concerning the bug report you found, go ahead and get involved, i.e. supply the missing code! – Ulrich Eckhardt Mar 10 '19 at 18:06
  • 1
    @UlrichEckhardt It was a formatting issue - apparently if you have the 3 backticks on the same line as your code the first line disappears. As for the bug report, I did file an issue on their github as well. – DoYouEvenCodeBro Mar 10 '19 at 18:08

2 Answers2

2

I have encountered the same problem to you when using Fedora 29. But after inspect the source code, it seems like mss uses x11 instead of xWayland to capture the screen and xWayland is default in Fedora. Switching the session to use x11 fixed my problem. The way to switch is mentioned here.

Hydra
  • 21
  • 2
1

Reduce the resolution of the screen in the range 700-400 and try it again. You might need to try different values in that range to make it precise.

artemis
  • 6,857
  • 11
  • 46
  • 99
chellathurai
  • 115
  • 1
  • 1
  • 8