XGetImage() failed when using mss
See original GitHub issueGeneral 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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
XGetImage Failed Error when using python MSS library on ...
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>, ' ...
Read more >MSS API — Python MSS latest documentation - Read the Docs
Error handler passed to X11.XSetErrorHandler() to catch any error that can happen when calling a X11 function. This will prevent Python interpreter crashes....
Read more >Help: XGetImage does not work
has anybody an idea, why this works without XGetImage(..) ... X Error of failed request: BadMatch (invalid parameter attributes) Major opcode of failed ......
Read more >x11vnc - allow VNC connections to real X11 displays
Use '-auth guess' to have x11vnc use its -findauth mechanism (described ... This enables a scheme were XGetImage() is not used to retrieve...
Read more >Xlib − C Language X Interface
unsigned long XAllPlanes(). Both return a value with all bits set to 1 suitable for use in a plane argument to a procedure....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 😄
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!!