launch_default_for_uri() 在某些系统上提供 URL 时引发异常

launch_default_for_uri() raises exception when an URL is provided on some systems

我正在使用 Gio 中的 launch_default_for_uri 函数(从 gi.repository 导入)在用户的默认浏览器中打开 URL。这在我的 phone 运行 postmarketOS 和我的桌面 运行 Fedora 32 上工作得很好,但在 Alpine Linux 虚拟机中我 运行 它反而提高了以下例外:

Traceback (most recent call last):
  File "giotest.py", line 3 in <module>
    Gio.AppInfo.launch_default_for_uri("https://whosebug.com")
gi.repository.GLib.Error: g-io-error-quark: Operation not supported (15)

这是我的最小可重现示例:

from gi.repository import Gio

Gio.AppInfo.launch_default_for_uri("https://whosebug.com")

我想这可能是因为我的虚拟机缺少依赖项,但我不确定是哪个。我应该怎么做才能在我的虚拟机中运行它?

您可能缺少 GIO 后端:安装 gvfs 应该会有帮助。

事实证明,至少在我的情况下,这是因为我没有设置默认浏览器。通过 Firefox 的设置将 Firefox 设置为我的默认设置解决了这个问题。