classification
Title: Webbrowser Module Cannot Find xdg-settings on OSX
Type: behavior Stage: resolved
Components: Library (Lib), macOS Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, ned.deily, ronaldoussoren, tony.diloreto
Priority: normal Keywords: newcomer friendly, patch

Created on 2020-09-10 06:15 by tony.diloreto, last changed 2020-11-08 12:06 by ronaldoussoren. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23075 merged ronaldoussoren, 2020-11-01 14:12
PR 23197 merged miss-islington, 2020-11-08 09:47
PR 23198 merged miss-islington, 2020-11-08 09:47
Messages (7)
msg376672 - (view) Author: Tony DiLoreto (tony.diloreto) Date: 2020-09-10 06:15
The following code does not work on many OSX installations of Python via homebrew:

>>> import webbrowser
>>> webbrowser.open("http://www.google.com")

And throws the following error stack trace:

  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/webbrowser.py", line 26, in register
    register_standard_browsers()
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/webbrowser.py", line 551, in register_standard_browsers
    raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
NotADirectoryError: [Errno 20] Not a directory: 'xdg-settings'



The only workaround right now is to modify webbrowser.py via the instructions here: https://github.com/jupyter/notebook/issues/3746#issuecomment-489259515.

Thank you for resolving.
msg378944 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-10-19 11:49
It is far from clear what's going on here. In particular, it not clear to my why check_output(['xdg-settings', ...]) would ever raise NotADirectoryError.

- What packages do you have installed through homebrew? 
- Is there an xdg-settings command installed on your system?
- Are DISPLAY or WAYLAND_DISPLAY in your shell environment?
msg379012 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2020-10-19 20:41
That does seem very odd but the issue clearly has been seen by multiple users. Since it shouldn't cause any negative effects, I'm in favor of just adding NotADirectoryError to the try/except list as suggested in the workaround and make the problem go away.
msg380141 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-11-01 14:12
I've created a PR that ignores this exception.
msg380543 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-11-08 09:46
New changeset 23831a7a90956e38b7d70304bb6afe30d37936de by Ronald Oussoren in branch 'master':
bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075)
https://github.com/python/cpython/commit/23831a7a90956e38b7d70304bb6afe30d37936de
msg380544 - (view) Author: miss-islington (miss-islington) Date: 2020-11-08 10:07
New changeset 371c33567a0b6afb93ffde2fb4564fe57a41945b by Miss Islington (bot) in branch '3.9':
bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075)
https://github.com/python/cpython/commit/371c33567a0b6afb93ffde2fb4564fe57a41945b
msg380547 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-11-08 12:06
New changeset db087f6d9ef9a7c873cd883ee120126fc0ca0c72 by Miss Islington (bot) in branch '3.8':
bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075) (GH-23198)
https://github.com/python/cpython/commit/db087f6d9ef9a7c873cd883ee120126fc0ca0c72
History
Date User Action Args
2020-11-08 12:06:41ronaldoussorensetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-11-08 12:06:20ronaldoussorensetmessages: + msg380547
2020-11-08 10:07:55miss-islingtonsetmessages: + msg380544
2020-11-08 09:47:31miss-islingtonsetpull_requests: + pull_request22098
2020-11-08 09:47:22miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request22097
2020-11-08 09:46:58ronaldoussorensetmessages: + msg380543
2020-11-01 14:12:53ronaldoussorensetmessages: + msg380141
2020-11-01 14:12:00ronaldoussorensetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request21995
2020-10-19 20:45:30ned.deilysetkeywords: + newcomer friendly
stage: needs patch
type: crash -> behavior
versions: - Python 3.5, Python 3.6, Python 3.7
2020-10-19 20:41:24ned.deilysetmessages: + msg379012
2020-10-19 11:49:25ronaldoussorensetmessages: + msg378944
2020-09-10 06:15:31tony.diloretocreate