This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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: open Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, ned.deily, ronaldoussoren, serhiy.storchaka, tony.diloreto
Priority: normal Keywords: newcomer friendly, patch

Created on 2020-09-10 06:15 by tony.diloreto, last changed 2022-04-11 14:59 by admin.

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 (8)
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
msg386632 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-02-08 17:07
Is it possible that your PATH contains a non-directory? Because it can give results a NotADirectoryError:

>>> subprocess.check_output(['xdg-settings', 'get', 'default-web-browser'], env={'PATH': '/etc/hosts'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython/Lib/subprocess.py", line 429, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/home/serhiy/py/cpython/Lib/subprocess.py", line 510, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/home/serhiy/py/cpython/Lib/subprocess.py", line 962, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/serhiy/py/cpython/Lib/subprocess.py", line 1840, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
NotADirectoryError: [Errno 20] Not a directory: 'xdg-settings'

Reopened because I afraid that there may be a severe configuration error hidden by silencing NotADirectoryError.

Could you please show os.environ['PATH'] on your computer?
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85920
2021-02-08 17:07:14serhiy.storchakasetstatus: closed -> open
nosy: + serhiy.storchaka
messages: + msg386632

2021-02-08 12:36:29ronaldoussorenlinkissue40361 superseder
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