Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageGrab.grabclipboard on Linux with both X11 and Wayland installed #7331

Closed
TheNooB2706 opened this issue Aug 11, 2023 · 0 comments · Fixed by #7332
Closed

ImageGrab.grabclipboard on Linux with both X11 and Wayland installed #7331

TheNooB2706 opened this issue Aug 11, 2023 · 0 comments · Fixed by #7332
Labels

Comments

@TheNooB2706
Copy link
Contributor

TheNooB2706 commented Aug 11, 2023

What did you do?

  1. Using grabclipboard on X11 session with wl-paste utility installed regardless if xclip is installed
  2. Using grabclipboard on Wayland session without wl-paste but xclip is installed

What did you expect to happen?

    • If xclip is installed, xclip command should be used
    • If xclip is not installed, raise NotImplementedError
  1. Raise NotImplementedError

What actually happened?

  1. wl-paste command is used instead of xclip
>>> ImageGrab.grabclipboard()
Failed to connect to a Wayland server
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[path redacted]/python3.11/site-packages/PIL/ImageGrab.py", line 144, in grabclipboard
    output = subprocess.check_output(["wl-paste", "-l"]).decode()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['wl-paste', '-l']' returned non-zero exit status 1.
  1. xclip is used and failed as it cannot access Wayland clipboard
>>> ImageGrab.grabclipboard()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[path redacted]/lib/python3.11/site-packages/PIL/ImageGrab.py", line 165, in grabclipboard
    raise ChildProcessError(msg)
ChildProcessError: xclip error: Error: target image/png not available

What are your OS, Python and Pillow versions?

  • OS: Debian 12
  • Python: 3.11.2
  • Pillow: 10.0.0
from PIL import ImageGrab

ImageGrab.grabclipboard()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants