在Ubuntu上使用python MSS库时,XGetImage失败,错误

问题描述 投票:1回答:1

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

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/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

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

我已经尝试以root身份运行它,但是给出了相同的输出。我在Google中找不到类似的问题。我也尝试在tmux之外运行它,也没有结果。

python linux x11 python-mss
1个回答
0
投票

降低屏幕的分辨率然后再试一次(将其保持在范围(700,400)内并稍微增大范围,直到找到正确的分辨率为止]

© www.soinside.com 2019 - 2024. All rights reserved.