首页 > 解决方案 > 在某些系统上提供 URL 时,launch_default_for_uri() 会引发异常

问题描述

我正在使用launch_default_for_urifrom Gio(imported from gi.repository) 的函数在用户的默认浏览器中打开一个 URL。这在运行 postmarketOS 的手机和运行 Fedora 32 的桌面上运行良好,但在 Alpine Linux 虚拟机中,我运行它会引发以下异常:

Traceback (most recent call last):
  File "giotest.py", line 3 in <module>
    Gio.AppInfo.launch_default_for_uri("https://stackoverflow.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://stackoverflow.com")

我想这可能是由于我的虚拟机中缺少依赖项,但我不确定那会是哪个。我该怎么做才能在我的虚拟机中完成这项工作?

标签: pythonglibgio

解决方案


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


推荐阅读