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 broken on Mac OS X when using the BROWSER variable
Type: Stage: patch review
Components: Library (Lib), macOS Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: _kud, andrei.avk, doughellmann, ehuss, eitan.adler, hudelgado, ned.deily, orsenthil, ronaldoussoren, sconseil
Priority: normal Keywords: patch

Created on 2015-08-29 10:01 by sconseil, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
webbrowser.patch sconseil, 2015-08-29 10:17
24955.diff hudelgado, 2020-07-27 03:16
Pull Requests
URL Status Linked Edit
PR 27751 open hudelgado, 2021-08-13 01:45
Messages (13)
msg249316 - (view) Author: Simon Conseil (sconseil) * Date: 2015-08-29 10:01
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
msg249317 - (view) Author: Simon Conseil (sconseil) * Date: 2015-08-29 10:17
New version of the patch to rename the _name attribute to name as in other BaseBrowser subclasses.
msg257198 - (view) Author: Erwann Mest (_kud) Date: 2015-12-29 16:20
+1

I've got like 3 apps which are broken.


- https://github.com/mkdocs/mkdocs/issues/465
- https://bugzilla.mozilla.org/show_bug.cgi?id=1012443
msg257962 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-11 14:52
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.
msg258120 - (view) Author: Simon Conseil (sconseil) * Date: 2016-01-12 22:43
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.
msg258122 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-12 23:43
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.
msg374220 - (view) Author: Hugo Delgado (hudelgado) * Date: 2020-07-25 02:19
I've bumped into this and won't mind working on it, is it ok for me to try to finish it?
msg374221 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2020-07-25 02:26
Hugo, please go ahead and a test for this patch.
msg374223 - (view) Author: Hugo Delgado (hudelgado) * Date: 2020-07-25 02:43
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?
msg374231 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2020-07-25 03:48
Hugo, I'd welcome such a change.
msg374358 - (view) Author: Hugo Delgado (hudelgado) * Date: 2020-07-27 03:16
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.
msg399394 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-08-11 13:59
Also see https://bugs.python.org/issue42255

Hugo: can you convert the patch to a PR?
msg399488 - (view) Author: Hugo Delgado (hudelgado) * Date: 2021-08-13 01:52
Yes, I've created a PR for it.

https://github.com/python/cpython/pull/27751

Happy to adapt it as needed.
Thanks
History
Date User Action Args
2022-04-11 14:58:20adminsetgithub: 69143
2021-08-17 16:46:29corona10setversions: + Python 3.11, - Python 2.7, Python 3.5, Python 3.6
2021-08-13 01:52:12hudelgadosetmessages: + msg399488
2021-08-13 01:45:42hudelgadosetstage: test needed -> patch review
pull_requests: + pull_request26228
2021-08-11 13:59:53andrei.avksetnosy: + andrei.avk
messages: + msg399394
2020-07-27 03:16:47hudelgadosetfiles: + 24955.diff

messages: + msg374358
2020-07-25 03:48:06orsenthilsetmessages: + msg374231
2020-07-25 02:43:30hudelgadosetmessages: + msg374223
2020-07-25 02:26:41orsenthilsetassignee: orsenthil
messages: + msg374221
2020-07-25 02:19:38hudelgadosetnosy: + hudelgado
messages: + msg374220
2019-12-30 19:18:33eitan.adlersetnosy: + eitan.adler
2017-07-22 00:58:35ehusssetnosy: + ehuss
2016-06-18 17:57:53doughellmannsetnosy: + doughellmann
2016-01-12 23:43:27orsenthilsetmessages: + msg258122
2016-01-12 22:43:04sconseilsetmessages: + msg258120
2016-01-11 14:52:30orsenthilsetversions: + Python 3.5, Python 3.6, - Python 3.4
nosy: + orsenthil

messages: + msg257962

stage: test needed
2015-12-29 16:20:53_kudsetnosy: + _kud
messages: + msg257198
2015-08-29 10:17:52sconseilsetfiles: - webbrowser.patch
2015-08-29 10:17:33sconseilsetfiles: + webbrowser.patch

messages: + msg249317
2015-08-29 10:01:40sconseilcreate