Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webbrowser Module Cannot Find xdg-settings on OSX #85920

Closed
tonydiloreto mannequin opened this issue Sep 10, 2020 · 9 comments
Closed

Webbrowser Module Cannot Find xdg-settings on OSX #85920

tonydiloreto mannequin opened this issue Sep 10, 2020 · 9 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes easy OS-mac stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tonydiloreto
Copy link
Mannequin

tonydiloreto mannequin commented Sep 10, 2020

BPO 41754
Nosy @ronaldoussoren, @ned-deily, @serhiy-storchaka, @miss-islington
PRs
  • bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings #23075
  • [3.9] bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075) #23197
  • [3.8] bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075) #23198
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2020-09-10.06:15:31.730>
    labels = ['OS-mac', 'easy', 'type-bug', '3.8', '3.9', '3.10', 'library']
    title = 'Webbrowser Module Cannot Find xdg-settings on OSX'
    updated_at = <Date 2021-02-08.17:07:14.253>
    user = 'https://bugs.python.org/tonydiloreto'

    bugs.python.org fields:

    activity = <Date 2021-02-08.17:07:14.253>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'macOS']
    creation = <Date 2020-09-10.06:15:31.730>
    creator = 'tony.diloreto'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41754
    keywords = ['patch', 'newcomer friendly']
    message_count = 8.0
    messages = ['376672', '378944', '379012', '380141', '380543', '380544', '380547', '386632']
    nosy_count = 5.0
    nosy_names = ['ronaldoussoren', 'ned.deily', 'serhiy.storchaka', 'miss-islington', 'tony.diloreto']
    pr_nums = ['23075', '23197', '23198']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41754'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @tonydiloreto
    Copy link
    Mannequin Author

    tonydiloreto mannequin commented Sep 10, 2020

    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: jupyter/notebook#3746 (comment).

    Thank you for resolving.

    @tonydiloreto tonydiloreto mannequin added 3.7 (EOL) end of life type-crash A hard crash of the interpreter, possibly with a core dump 3.10 only security fixes 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir OS-mac labels Sep 10, 2020
    @ronaldoussoren
    Copy link
    Contributor

    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?

    @ned-deily
    Copy link
    Member

    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.

    @ned-deily ned-deily added easy type-bug An unexpected behavior, bug, or error and removed 3.7 (EOL) end of life type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 19, 2020
    @ronaldoussoren
    Copy link
    Contributor

    I've created a PR that ignores this exception.

    @ronaldoussoren
    Copy link
    Contributor

    New changeset 23831a7 by Ronald Oussoren in branch 'master':
    bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075)
    23831a7

    @miss-islington
    Copy link
    Contributor

    New changeset 371c335 by Miss Islington (bot) in branch '3.9':
    bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075)
    371c335

    @ronaldoussoren
    Copy link
    Contributor

    New changeset db087f6 by Miss Islington (bot) in branch '3.8':
    bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075) (GH-23198)
    db087f6

    @serhiy-storchaka
    Copy link
    Member

    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?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @ronaldoussoren
    Copy link
    Contributor

    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?

    Ignoring NotADirectoryError can ignore a configuration error, but this does match the behaviour of shells:

    $ PATH=/etc/hosts ls                                                                                                             
    zsh: command not found: ls

    IMHO ignoring NotADirectory is the right thing to do here, there is no xdc-settings command found on the user's PATH even if that contains an invalid entry (not a directory or not existing). This avoids a strange error when the user has a directory on PATH that does not exist. One way this might happen is by having a shell profile that's shared between machines without having the same directory setup on all of them, I generally have the same PATH setting on all my test machines including $HOME/.local/bin but don't have that directory on all of them at all times.

    I'm therefore reclining the issue.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes easy OS-mac stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants