XGetImage在Ubuntu上使用Python MSS库时失败的错误



我在使用MSS时,在Ubuntu 18.10上遇到错误(如果很重要)。这是我的代码(从文档中的示例中获取,以及一些额外的错误输出):

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)

这是我使用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)}

如果有帮助,则如果我不捕获异常(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

我在虚拟环境中运行它,其中我的pipfile.lock报告MSS版本4.0.2

我尝试将其作为根而运行,但这给出了相同的输出。我在Google中找不到类似的问题。我还尝试在TMUX之外运行它,这也没有结果。

我在使用Fedora 29时遇到了同样的问题。但是,在检查源代码后,似乎mss使用x11而不是xWayland来捕获屏幕,而xWayland在Fedora中默认是。切换会话以使用x11解决了我的问题。这里提到开关的方式。

在700-400范围内减少屏幕的分辨率,然后重试。您可能需要在该范围内尝试不同的值才能使其准确。

相关内容

最新更新