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 broken on Mac OS X when using the BROWSER variable #69143

Closed
sconseil mannequin opened this issue Aug 29, 2015 · 15 comments
Closed

webbrowser broken on Mac OS X when using the BROWSER variable #69143

sconseil mannequin opened this issue Aug 29, 2015 · 15 comments
Assignees
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes OS-mac stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sconseil
Copy link
Mannequin

sconseil mannequin commented Aug 29, 2015

BPO 24955
Nosy @ronaldoussoren, @orsenthil, @ned-deily, @dhellmann, @grimreaper, @hudelgado, @akulakov
PRs
  • bpo-24955: Fix webbrowser broken on Mac OS X when using the BROWSER variable #27751
  • Files
  • webbrowser.patch
  • 24955.diff
  • 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 = 'https://github.com/orsenthil'
    closed_at = None
    created_at = <Date 2015-08-29.10:01:40.688>
    labels = ['OS-mac', 'library', '3.11']
    title = 'webbrowser broken on Mac OS X when using the BROWSER variable'
    updated_at = <Date 2021-08-17.16:46:29.259>
    user = 'https://bugs.python.org/sconseil'

    bugs.python.org fields:

    activity = <Date 2021-08-17.16:46:29.259>
    actor = 'corona10'
    assignee = 'orsenthil'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'macOS']
    creation = <Date 2015-08-29.10:01:40.688>
    creator = 'sconseil'
    dependencies = []
    files = ['40291', '49341']
    hgrepos = []
    issue_num = 24955
    keywords = ['patch']
    message_count = 13.0
    messages = ['249316', '249317', '257198', '257962', '258120', '258122', '374220', '374221', '374223', '374231', '374358', '399394', '399488']
    nosy_count = 10.0
    nosy_names = ['ehuss', 'ronaldoussoren', 'orsenthil', 'ned.deily', 'doughellmann', 'eitan.adler', 'sconseil', '_kud', 'hudelgado', 'andrei.avk']
    pr_nums = ['27751']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue24955'
    versions = ['Python 3.11']

    @sconseil
    Copy link
    Mannequin Author

    sconseil mannequin commented Aug 29, 2015

    Hi,

    There is an issue in the webbrowser module for Mac OS when the BROWSER environment variable is set:

    Python 2.7.10 (default, Jul 14 2015, 19:46:27)
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    Jedi is not installed, falling back to readline
    Python shell history: /Users/simon/.pythonhistory
    >>> import webbrowser
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/webbrowser.py", line 669, in <module>
        cmd = _synthesize(cmdline, -1)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/webbrowser.py", line 94, in _synthesize
        if controller and name.lower() == controller.basename:
    AttributeError: 'MacOSXOSAScript' object has no attribute 'basename'

    If I unset BROWSER then it works fine. The issue is that the MacOSXOSAScript class overrides BaseBrowser's init without redifining the basename attribute. So a simple fix is to remove the __init__ from MacOSXOSAScript (and I guess the same applies to the MacOSX class). The same issue applies to python 3.4

    @sconseil sconseil mannequin added stdlib Python modules in the Lib dir OS-mac labels Aug 29, 2015
    @sconseil
    Copy link
    Mannequin Author

    sconseil mannequin commented Aug 29, 2015

    New version of the patch to rename the _name attribute to name as in other BaseBrowser subclasses.

    @kud
    Copy link
    Mannequin

    kud mannequin commented Dec 29, 2015

    @orsenthil
    Copy link
    Member

    The patch is correct and will fix the issue. It will require test coverage to be complete so that we don't land upon similar issues in future.

    @sconseil
    Copy link
    Mannequin Author

    sconseil mannequin commented Jan 12, 2016

    I have looked at the webbrowser tests and it seems not so easy: currently the MacOS browser classes are not tested, and they don't the GenericBrowser base class. Instead they use custom code with os.popen, so it would require some work either replace os.popen with subprocess.Popen, or to mock the os.popen calls. I'm not sure I will the time to dig into this.

    @orsenthil
    Copy link
    Member

    Simon, sure. It is just for someone, either commiters or other interested folks to add the tests on top of your patch. Agree with you that more change is required to add the required tests.

    @hudelgado
    Copy link
    Mannequin

    hudelgado mannequin commented Jul 25, 2020

    I've bumped into this and won't mind working on it, is it ok for me to try to finish it?

    @orsenthil
    Copy link
    Member

    Hugo, please go ahead and a test for this patch.

    @orsenthil orsenthil self-assigned this Jul 25, 2020
    @hudelgado
    Copy link
    Mannequin

    hudelgado mannequin commented Jul 25, 2020

    Ok, I'm thinking in also replace the os.popen calls with subprocess.Popen to keep consistency with existing tests.
    Do you think it's a good approach? Or should be better to just add some tests around the current implementation?

    @orsenthil
    Copy link
    Member

    Hugo, I'd welcome such a change.

    @hudelgado
    Copy link
    Mannequin

    hudelgado mannequin commented Jul 27, 2020

    I took a look at it and have a some more questions.
    The class MacOSX(BaseBrowser) seems to be broken because it uses 'OpenUrl' which doesn't work in most recent versions of applescript, also that class doesn't seem to be used anywhere, is it ok to remove it, or should left it as is?
    Although that class isn't used it contained an hack to open local files that didn't exist in the class MacOSXOSAScript(BaseBrowser), i've added that hack to the MacOSXOSAScript.
    Can you validate if everything seems ok with this changes?
    I'm happy to adjust things according to what you suggest.

    @akulakov
    Copy link
    Contributor

    Also see https://bugs.python.org/issue42255

    Hugo: can you convert the patch to a PR?

    @hudelgado
    Copy link
    Mannequin

    hudelgado mannequin commented Aug 13, 2021

    Yes, I've created a PR for it.

    #27751

    Happy to adapt it as needed.
    Thanks

    @corona10 corona10 added the 3.11 only security fixes label Aug 17, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @arhadthedev arhadthedev added type-bug An unexpected behavior, bug, or error 3.10 only security fixes 3.12 bugs and security fixes labels May 25, 2023
    @ronaldoussoren
    Copy link
    Contributor

    This works in the current releases for 3.9, 3.10, 3.11 and 3.12: BROWSER=chrome python3 -m webbrowser http://www.python.org/.

    That means this issue is no longer needed.

    @ronaldoussoren ronaldoussoren closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2023
    @schiebel
    Copy link

    schiebel commented Jan 5, 2024

    I do not see the behavior that @ronaldoussoren describes:

    bash$ python -V
    Python 3.10.13
    bash$ BROWSER=chrome python -m webbrowser http://www.python.org/ ## OPENS IN DEFAULT BROWSER
    
    bash$ BROWSER=safari python -m webbrowser http://www.python.org/ ## ALSO OPENS IN DEFAULT BROWSER
    
    bash$ BROWSER=/Applications/Safari.app/Contents/MacOS/Safari python -m webbrowser http://www.python.org/
    Traceback (most recent call last):
      File "/Users/drs/develop/python/conda/envs/bokeh-32/lib/python3.10/runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/Users/drs/develop/python/conda/envs/bokeh-32/lib/python3.10/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "/Users/drs/develop/python/conda/envs/bokeh-32/lib/python3.10/webbrowser.py", line 717, in <module>
        main()
      File "/Users/drs/develop/python/conda/envs/bokeh-32/lib/python3.10/webbrowser.py", line 712, in main
        open(url, new_win)
      File "/Users/drs/develop/python/conda/envs/bokeh-32/lib/python3.10/webbrowser.py", line 83, in open
        register_standard_browsers()
      File "/Users/drs/develop/python/conda/envs/bokeh-32/lib/python3.10/webbrowser.py", line 591, in register_standard_browsers
        cmd = _synthesize(cmdline, preferred=True)
      File "/Users/drs/develop/python/conda/envs/bokeh-32/lib/python3.10/webbrowser.py", line 127, in _synthesize
        if controller and name.lower() == controller.basename:
    AttributeError: 'MacOSXOSAScript' object has no attribute 'basename'
    bash$ 
    

    Chrome is my default browser, but sometimes it is helpful to be able to test in Safari.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes 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

    6 participants