pyscreenshot无需登录即可获取远程windows服务器的屏幕截图

python2脚本是由系统守护进程(如SaltStack,进程用户是管理员)执行的,该脚本运行良好,并在我连接并登录服务器时保存了屏幕截图,但在没有人登录的情况下会引发错误。

import pyscreenshot
getPic = pyscreenshot.grab(bbox=(0, 0, 1920, 1080)) ## line 43
# getPic = pyscreenshot.grab() ## work as same as before line
getPic.save('screenshot.png')

错误信息:

Traceback (most recent call last):
  File ".../.../get_desktop_screenshot.py", line 43, in <module>
  File "C:\Python27\lib\site-packages\pyscreenshot\__init__.py", line 43, in grab
    return _grab(childprocess=childprocess, backend=backend, bbox=bbox)
  File "C:\Python27\lib\site-packages\pyscreenshot\__init__.py", line 29, in _grab
    return childprocess_grab(_grab_simple, backend, bbox)
  File "C:\Python27\lib\site-packages\pyscreenshot\childproc.py", line 34, in childprocess_grab
    return childprocess_grab_popen(backend, bbox)
  File "C:\Python27\lib\site-packages\pyscreenshot\childproc.py", line 54, in childprocess_grab_popen
    raise FailedBackendError(p)
pyscreenshot.loader.FailedBackendError: <EasyProcess cmd_param=['C:\\Python27\\python.exe', '-m', 'pyscreenshot.cli.grab_to_file', 'c:\\users\\admini~1\\appdata\\local\\temp\\pyscreenshothgubzc\\screenshot.png', '0', '0', '1920', '1080', '--backend', ''] cmd=['C:\\Python27\\python.exe', '-m', 'pyscreenshot.cli.grab_to_file', 'c:\\users\\admini~1\\appdata\\local\\temp\\pyscreenshothgubzc\\screenshot.png', '0', '0', '1920', '1080', '--backend', ''] oserror=None return_code=1 stdout="" stderr="Traceback (most recent call last):

  File "C:\Python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\lib\site-packages\pyscreenshot\cli\grab_to_file.py", line 8, in <module>
    def main(filename, x1, y1, x2, y2, backend=""):
  File "C:\Python27\lib\site-packages\entrypoint2\__init__.py", line 440, in entrypoint
    return func(**kwargs)
  File "C:\Python27\lib\site-packages\pyscreenshot\cli\grab_to_file.py", line 28, in main
    im = pyscreenshot.grab(bbox=bbox, childprocess=False, backend=backend)
  File "C:\Python27\lib\site-packages\pyscreenshot\__init__.py", line 43, in grab
    return _grab(childprocess=childprocess, backend=backend, bbox=bbox)
  File "C:\Python27\lib\site-packages\pyscreenshot\__init__.py", line 31, in _grab
    return _grab_simple(backend, bbox, filename)
  File "C:\Python27\lib\site-packages\pyscreenshot\__init__.py", line 17, in _grab_simple
    return backend_obj.grab(bbox)
  File "C:\Python27\lib\site-packages\pyscreenshot\plugins\pil.py", line 17, in grab
    return self.ImageGrab.grab(bbox)
  File "C:\Python27\lib\site-packages\PIL\ImageGrab.py", line 41, in grab
    size, data = grabber()
IOError: screen grab failed" timeout_happened=False>

转载请注明出处:http://www.hnsdbxf.com/article/20230526/2123524.html