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

Crash - "IndexError and xdg-portal Error Code 2 on Ubuntu 22.04.3 LTS with Wayland" #533

Closed
jakemerson opened this issue Oct 3, 2023 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@jakemerson
Copy link

What happened?

When running NormCap on Ubuntu 22.04.3 LTS using Wayland, I encounter an IndexError and an error message indicating "Error code 2 received from xdg-portal!"

14:52:54 - ERROR - normcap.screengrab.dbus_portal:103 - Error code 2 received from xdg-portal!
14:52:54 - CRITICAL - normcap:161 - Uncaught exception! Quitting NormCap!

System:

{  'cli_args': '/home/REDACTED/.local/bin/normcap',
   'config_directory': PosixPath('/home/REDACTED/.config/normcap'),
   'desktop_environment': <DesktopEnvironment.GNOME: 1>,
   'display_manager_is_wayland': True,
   'envs': {'LD_LIBRARY_PATH': None, 'TESSDATA_PREFIX': None},
   'is_briefcase_package': False,
   'is_flatpak_package': False,
   'normcap_version': '0.4.4',
   'platform': 'linux',
   'pyside6_version': '6.5.1',
   'qt_library_path': '/home/REDACTED/.local/lib/python3.10/site-packages/PySide6/Qt/plugins, '
                      '/usr/bin',
   'qt_version': '6.5.1',
   'ressources_path': PosixPath('/home/REDACTED/.local/lib/python3.10/site-packages/normcap/resources'),
   'screens': [  Screen(is_primary=True,
                        device_pixel_ratio=1.0,
                        rect=Rect(left=0, top=0, right=1920, bottom=1080),
                        index=0,
                        screenshot=None)],
   'tessdata_path': None,
   'tesseract_path': PosixPath('/usr/bin/tesseract')}

Variables:

                    'code': 2,
                    'message': <PySide6.QtDBus.QDBusMessage(type=Signal, service=":1.75", path="/org/freedesktop/portal/desktop/request/1_367/normcap_fcadefcg", interface="org.freedesktop.portal.Request", member="Response", signature="ua{sv}", contents=(2, [Argument: a{sv} {}]) ) at 0x7f7da1867b40>,
                    'msg': 'Error code 2 received from xdg-portal!',
                    'self': 'REDACTED'}}

Exception:

  IndexError: list index out of range

Traceback:

  File "/home/REDACTED/.local/lib/python3.10/site-packages/normcap/screengrab/dbus_portal.py", line 107, in got_signal
    uri = str(message).split('[Variant(QString): "')[1]

14:52:54 - CRITICAL - normcap:192 - Please open an issue with the output above on https://github.com/dynobo/normcap/issues

How did you install NormCap?

AppImage (Linux)

Operating System + Version?

Ubuntu 22.04.3 LTS

[Linux only] Display Server (DS) + Desktop environment (DE)?

DS:Wayland, DE:GNOME

Debug log output?*

14:58:06 - INFO    - normcap:30 - Start NormCap v0.4.4
14:58:06 - DEBUG   - normcap:81 - Set XCURSOR_SIZE=24
14:58:06 - DEBUG   - normcap:86 - Set QT_QPA_PLATFORM=wayland
14:58:06 - DEBUG   - normcap.gui.tray:60 - System info:
{'cli_args': '/tmp/.mount_NormCaMMbQPY/usr/app/normcap/__main__.py -v debug', 'is_briefcase_package': True, 'is_flatpak_package': False, 'platform': 'linux', 'pyside6_version': '6.5.1', 'qt_version': '6.5.1', 'qt_library_path': '/tmp/.mount_NormCaMMbQPY/usr/app_packages/PySide6/Qt/plugins, /tmp/.mount_NormCaMMbQPY/usr/python/bin', 'config_directory': PosixPath('/home/emerson/.config/normcap'), 'normcap_version': '0.4.4', 'ressources_path': PosixPath('/tmp/.mount_NormCaMMbQPY/usr/app/normcap/resources'), 'tesseract_path': PosixPath('/tmp/.mount_NormCaMMbQPY/usr/bin/tesseract'), 'tessdata_path': PosixPath('/home/emerson/.config/normcap/tessdata'), 'envs': {'TESSDATA_PREFIX': None, 'LD_LIBRARY_PATH': None}, 'desktop_environment': <DesktopEnvironment.GNOME: 1>, 'display_manager_is_wayland': True, 'screens': [Screen(is_primary=True, device_pixel_ratio=1.0, rect=Rect(left=0, top=0, right=1920, bottom=1080), index=0, screenshot=None)]}
14:58:06 - DEBUG   - normcap.gui.tray:342 - Listen on local socket v0.4.4-normcap.
14:58:06 - DEBUG   - normcap.gui.settings:128 - Skip update of non existing setting (cli_mode: False)
14:58:06 - DEBUG   - normcap.gui.settings:128 - Skip update of non existing setting (background_mode: False)
14:58:06 - DEBUG   - normcap.screengrab.utils:79 - Detected Gnome Version: 42.9
14:58:06 - DEBUG   - normcap.screengrab:37 - Select capture method DBUS portal
14:58:06 - DEBUG   - normcap.screengrab.dbus_portal:196 - Request screenshot with interactive=False
14:58:06 - DEBUG   - normcap.screengrab.dbus_portal:79 - Request accepted
14:58:06 - ERROR   - normcap.screengrab.dbus_portal:103 - Error code 2 received from xdg-portal!
14:58:06 - DEBUG   - normcap.screengrab.dbus_portal:106 - Parse response
Traceback (most recent call last):
  File "/tmp/.mount_NormCaMMbQPY/usr/app/normcap/screengrab/dbus_portal.py", line 107, in got_signal
    uri = str(message).split('[Variant(QString): "')[1]
IndexError: list index out of range
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/.mount_NormCaMMbQPY/usr/python/lib/python3.10/runpy.py", line 224, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/tmp/.mount_NormCaMMbQPY/usr/python/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/tmp/.mount_NormCaMMbQPY/usr/python/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/.mount_NormCaMMbQPY/usr/app/normcap/__main__.py", line 6, in <module>
    main()
  File "/tmp/.mount_NormCaMMbQPY/usr/app/normcap/app.py", line 57, in main
    tray = SystemTray(app, vars(args))
  File "/tmp/.mount_NormCaMMbQPY/usr/app/normcap/gui/tray.py", line 100, in __init__
    self._update_screenshots(delayed=False)
  File "/tmp/.mount_NormCaMMbQPY/usr/app/normcap/gui/tray.py", line 425, in _update_screenshots
    screens = capture()
  File "/tmp/.mount_NormCaMMbQPY/usr/app/normcap/screengrab/dbus_portal.py", line 197, in capture
    result = _synchronized_capture(interactive=False)
  File "/tmp/.mount_NormCaMMbQPY/usr/app/normcap/screengrab/dbus_portal.py", line 152, in _synchronized_capture
    raise error
normcap.screengrab.ScreenshotResponseError: Error code 2 received from xdg-portal!
@jakemerson jakemerson added bug Something isn't working triage Needs confirmation and priotization labels Oct 3, 2023
@dynobo dynobo removed the triage Needs confirmation and priotization label Oct 4, 2023
@dynobo dynobo self-assigned this Oct 4, 2023
@dynobo
Copy link
Owner

dynobo commented Oct 4, 2023

Thanks for reporting, @jakemerson.

I also started to get this Error on my Arch Linux today, after some system updates. Working on it.

@dynobo
Copy link
Owner

dynobo commented Oct 4, 2023

There must have been changes in xdg-desktop-portal. For some screenshot application, now a new pop-up is shown like "Do you want to grant screenshot permission to this app?". However, it doesn't seem to be shown for NormCap. (At least not reliably. Somehow it appeared once, and I was able to grant the permission, and it is working again for me.)

Unfortunately, I don't know (yet), where this new permission is actually stored. It's doesn't seem to be managed by "Settings" -> "Apps", which in Gnome is usually the place to grant permissions. But screenshot permission only show up for FlatPak applications there, as usual).

If someone has more info, that'd be great! 🙂

@dynobo dynobo pinned this issue Oct 4, 2023
@dynobo
Copy link
Owner

dynobo commented Oct 4, 2023

@jakemerson, can you please try to run with using strace, and see if that helps? (Just ignore the huge log output, it's not helpful here. I'm only curious if the screenshot works again.)

strace ./NormCap-0.4.4-x86_64.AppImage

PS: Your log file seems to be generated by the Python version of NormCap, not the AppImage as you reported in the ticket. If this is true, run

strace normcap
# or
strace ~/.local/bin/normcap

@jakemerson
Copy link
Author

Hello, thanks for responding to me.
I have the Python version and the AppImage version.
I ran it with strace but both still don't work

@dynobo
Copy link
Owner

dynobo commented Oct 6, 2023

Thanks for trying, @jakemerson.

One more idea: Can you try running

flatpak permission-set screenshot screenshot com.github.dynobo.normcap yes

and then retry starting NormCap? If a modal dialog appears, asking you to "share" a screenshot or "grant permission", confirm that.

Does that work?

PS: You can show all permissions with:

flatpak permissions

and revert the added permission by running

flatpak permission-reset com.github.dynobo.normcap

@jakemerson
Copy link
Author

I installed flatpak version and set the permission, but still dont work

I received that output:

22:39:09 - ERROR - normcap.screengrab.dbus_portal:103 - Error code 2 received from xdg-portal!
22:39:09 - CRITICAL - normcap:161 - Uncaught exception! Quitting NormCap!

System:

{  'cli_args': '/app/bin/normcap',
   'config_directory': PosixPath('/home/REDACTED/.var/app/com.github.dynobo.normcap/config/normcap'),
   'desktop_environment': <DesktopEnvironment.GNOME: 1>,
   'display_manager_is_wayland': True,
   'envs': {'LD_LIBRARY_PATH': '', 'TESSDATA_PREFIX': '/app/share'},
   'is_briefcase_package': False,
   'is_flatpak_package': True,
   'normcap_version': '0.4.4',
   'platform': 'linux',
   'pyside6_version': '6.5.1',
   'qt_library_path': '/usr/share/runtime/lib/plugins, '
                      '/app/lib/python3.10/site-packages/PySide6/Qt/plugins, '
                      '/usr/bin',
   'qt_version': '6.5.1',
   'ressources_path': PosixPath('/app/lib/python3.10/site-packages/normcap/resources'),
   'screens': [  Screen(is_primary=True,
                        device_pixel_ratio=1.0,
                        rect=Rect(left=0, top=0, right=1920, bottom=1080),
                        index=0,
                        screenshot=None)],
   'tessdata_path': PosixPath('/home/REDACTED/.var/app/com.github.dynobo.normcap/config/normcap/tessdata'),
   'tesseract_path': PosixPath('/app/bin/tesseract')}

Variables:

                    'code': 2,
                    'message': <PySide6.QtDBus.QDBusMessage(type=Signal, service=":1.75", path="/org/freedesktop/portal/desktop/request/1_574/normcap_faaaiadc", interface="org.freedesktop.portal.Request", member="Response", signature="ua{sv}", contents=(2, [Argument: a{sv} {}]) ) at 0x7fdc2503c680>,
                    'msg': 'Error code 2 received from xdg-portal!',
                    'self': 'REDACTED'}}

Exception:

  IndexError: list index out of range

Traceback:

  File "/app/lib/python3.10/site-packages/normcap/screengrab/dbus_portal.py", line 107, in got_signal
    uri = str(message).split('[Variant(QString): "')[1]

22:39:09 - CRITICAL - normcap:192 - Please open an issue with the output above on https://github.com/dynobo/normcap/issues

@dynobo dynobo unpinned this issue Oct 8, 2023
@dynobo
Copy link
Owner

dynobo commented Oct 8, 2023

Thanks again, @jakemerson. I just released v0.5.0-beta1, which aims to also improve the permission handling on Wayland systems. Do you want to give the AppImage a try?

If that also doesn't work, could you please run flatpak permissions screenshot and post the output here?

@dynobo dynobo pinned this issue Oct 8, 2023
@jakemerson
Copy link
Author

Now apear a popup :
image

but when i click on "OK" nothing happens.

And then i receive this output:

./NormCap-0.5.0-beta1-x86_64.AppImage
15:35:11 - ERROR - normcap.screengrab.dbus_portal:129 - Permission denied for Screenshot via xdg-portal! Message: <PySide6.QtDBus.QDBusMessage(type=Signal, service=":1.74", path="/org/freedesktop/portal/desktop/request/1_406/normcap_ibbhhfbe", interface="org.freedesktop.portal.Request", member="Response", signature="ua{sv}", contents=(2, [Argument: a{sv} {}]) ) at 0x7fc6122f8d40>
15:35:11 - WARNING - normcap.screengrab.permissions:205 - Screenshot permissions on Wayland seem missing.
Traceback (most recent call last):
File "/tmp/.mount_NormCa8gKuu3/usr/app/normcap/screengrab/permissions.py", line 200, in _dbus_portal_has_screenshot_permission
result = dbus_portal.capture()
File "/tmp/.mount_NormCa8gKuu3/usr/app/normcap/screengrab/dbus_portal.py", line 223, in capture
result = _synchronized_capture(interactive=False)
File "/tmp/.mount_NormCa8gKuu3/usr/app/normcap/screengrab/dbus_portal.py", line 200, in _synchronized_capture
raise error
normcap.screengrab.exceptions.ScreenshotPermissionError: Permission denied for Screenshot via xdg-portal! Message: <PySide6.QtDBus.QDBusMessage(type=Signal, service=":1.74", path="/org/freedesktop/portal/desktop/request/1_406/normcap_ibbhhfbe", interface="org.freedesktop.portal.Request", member="Response", signature="ua{sv}", contents=(2, [Argument: a{sv} {}]) ) at 0x7fc6122f8d40>
15:36:02 - ERROR - normcap.screengrab.dbus_portal:129 - Permission denied for Screenshot via xdg-portal! Message: <PySide6.QtDBus.QDBusMessage(type=Signal, service=":1.74", path="/org/freedesktop/portal/desktop/request/1_406/normcap_ggdaafii", interface="org.freedesktop.portal.Request", member="Response", signature="ua{sv}", contents=(2, [Argument: a{sv} {}]) ) at 0x7fc6119e99c0>
15:36:02 - CRITICAL - normcap:138 - Uncaught exception!
Traceback (most recent call last):
File "/tmp/.mount_NormCa8gKuu3/usr/app/normcap/screengrab/permissions.py", line 181, in accept_button_pressed
self.capture = dbus_portal._synchronized_capture(interactive=True)
File "/tmp/.mount_NormCa8gKuu3/usr/app/normcap/screengrab/dbus_portal.py", line 200, in _synchronized_capture
raise error
normcap.screengrab.exceptions.ScreenshotPermissionError: Permission denied for Screenshot via xdg-portal! Message: <PySide6.QtDBus.QDBusMessage(type=Signal, service=":1.74", path="/org/freedesktop/portal/desktop/request/1_406/normcap_ggdaafii", interface="org.freedesktop.portal.Request", member="Response", signature="ua{sv}", contents=(2, [Argument: a{sv} {}]) ) at 0x7fc6119e99c0>
15:36:02 - CRITICAL - normcap:141 - System info: {'normcap_version': '0.5.0-beta1', 'python_version': '3.10.13', 'cli_args': '/tmp/.mount_NormCa8gKuu3/usr/app/normcap/main.py', 'is_briefcase_package': True, 'is_flatpak_package': False, 'platform': 'linux', 'desktop_environment': <DesktopEnvironment.GNOME: 1>, 'display_manager_is_wayland': True, 'pyside6_version': '6.5.3', 'qt_version': '6.5.3', 'qt_library_path': '/tmp/.mount_NormCa8gKuu3/usr/app_packages/PySide6/Qt/plugins, /tmp/.mount_NormCa8gKuu3/usr/python/bin', 'locale': 'pt_PT', 'config_directory': PosixPath('/home/emerson/.config/normcap'), 'resources_path': PosixPath('/tmp/.mount_NormCa8gKuu3/usr/app/normcap/resources'), 'tesseract_path': PosixPath('/tmp/.mount_NormCa8gKuu3/usr/bin/tesseract'), 'tessdata_path': PosixPath('/home/emerson/.config/normcap/tessdata'), 'envs': {'TESSDATA_PREFIX': None, 'LD_LIBRARY_PATH': None}, 'screens': [Screen(left=0, top=0, right=1919, bottom=1079, device_pixel_ratio=1.0, index=0, screenshot=None)]}
15:36:02 - CRITICAL - normcap:142 - Unfortunately, NormCap has to be terminated due to an unknown problem.
Please help improve NormCap by reporting this error, including the output above, on
https://github.com/dynobo/normcap/issues/new
Thanks!

@dynobo
Copy link
Owner

dynobo commented Oct 8, 2023

Hi @jakemerson, thanks for this info, I think we are getting closer. I just launched a VM with Ubuntu 22.04.3, and I really think the issue is a usual suspect: Waylands xdg portal permission handling. (Unfortunately, it is quite cumbersome to work with it as a developer, the implementation is constantly changing and its documentation poor).

For me, on that fresh install, it behaved like this:
I launch ./NormCap[..].AppImage and this native screen sharing dialog appears:

Screenshot from 2023-10-09 00-17-43 resized

(Now that I see it, I remember that this Gnome version, screenshot permissions could not be granted permanently, instead one had to deal with this sharing dialog on every NormCap capture, see #264).

However, if I click "share", then NormCap opens (and also this NormCap Error popup you posted, which actually doesn't help at all in that Gnome version... 🙈 )

I'm wondering: Don't you see those native screen sharing dialogs at all? How do other screenshot applications behave, e.g. flameshot? Don't you see this dialog there, either?
(The internal "Gnome Screenshot" tool is special, as it is well integrated with the system)

@jakemerson
Copy link
Author

I don't see any dialog
Flameshot didn't work either
I don't think any screenshot or OCR app will work 🥲

But, thanks for your help

@dynobo
Copy link
Owner

dynobo commented Oct 9, 2023

@jakemerson, okay, hard to say where the problem is, in that case. May last idea would be to check, if you have xdg-desktop-portal installed correctly. This is what was installed in my Ubuntu 22.04.3 VM by default:

$ sudo apt list --installed xdg-desktop-portal*
xdg-desktop-portal-gnome/jammy-updates, now 42.1-0ubuntu1 amd [installed, automatic]
xdg-desktop-portal-gtk/jammy, now 1.14.0-1build1 amd [installed, automatic]
xdg-desktop-portal/jammy-updates, now 1.14.4-1ubuntu2~22.04.1 amd [installed, automatic]

I'm closing this issue for now, as I'm not able to reproduce this issue on Ubuntu 22.04.3 with Wayland, so it might be something configuration specific.

If any new information come up, or if someone else has the same issue on this system, please don't hesitate to reopen! 🙂

@dynobo dynobo closed this as completed Oct 9, 2023
@jakemerson
Copy link
Author

Hi again. Somehow now a popup appears and ask me to share the screenshot with normcap. And then it works!

@dynobo
Copy link
Owner

dynobo commented Oct 25, 2023

Thanks for letting me know, @jakemerson!

@dynobo dynobo unpinned this issue Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants