pythonglibgio

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


I'm using the launch_default_for_uri function from Gio (imported from gi.repository) to open an URL in the user's default browser. This works just fine on my phone running postmarketOS and my desktop running Fedora 32, but in an Alpine Linux virtual machine I'm running it instead raises the following exception:

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)

Here's my minimal reproducible example:

from gi.repository import Gio

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

I imagine this might be due to a missing dependency in my virtual machine, but I'm not sure which that would be. What might I do to make this work in my virtual machine?


Solution

  • It turns out that this at least in my case was due to that I didn't have a default browser set. Setting Firefox as my default through Firefox' settings resolved this.