flaskwebgui icon indicating copy to clipboard operation
flaskwebgui copied to clipboard

`webbrowser.Error` raised during import

Open paco-sevilla opened this issue 2 months ago • 0 comments

In some environments (e.g. Docker containers), webbrowser.Error: could not locate runnable browser is raised during import while trying to set DEFAULT_BROWSER.

I'm aware that flaskwebgui will (probably) not work in that case and therefore, raising an Exception is appropriate. My point is simply that it is awkward that this exception is raised during import, instead of when calling a function or instantiating a class.

The fix could be quite simple: Since DEFAULT_BROWSER is only used once, we could make it a local variable/constant of the find_browser_in_paths function, instead of global.

To reproduce:

$ docker run -it python bash
root@0dd63677aa98:/# pip install -q -q flaskwebgui
root@0dd63677aa98:/# python
Python 3.14.0 (main, Nov 18 2025, 11:48:42) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flaskwebgui
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import flaskwebgui
  File "/usr/local/lib/python3.14/site-packages/flaskwebgui.py", line 30, in <module>
    DEFAULT_BROWSER = webbrowser.get().name
                      ~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.14/webbrowser.py", line 68, in get
    raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser

flaskwebgui Version: 1.1.8

paco-sevilla avatar Dec 01 '25 10:12 paco-sevilla