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: default webbrowser fails on macOS Sierra 10.12.5
Type: behavior Stage: resolved
Components: Library (Lib), macOS Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: Andrew.Jaffe, Kevin Ballard, Rudi Grams, alangpierce, dasm, ehuss, glyph, ned.deily, ronaldoussoren, tgecho
Priority: normal Keywords:

Created on 2017-05-17 19:44 by Andrew.Jaffe, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (17)
msg293881 - (view) Author: Andrew Jaffe (Andrew.Jaffe) Date: 2017-05-17 19:50
On the newly-released macOS Sierra 10.12.5, the default web browser which is meant to returned by webbrowser.get() gives an error. Specifically:

    >>> import webbrowser
    >>> br = webbrowser.get()
    >>> br.open("http://python.org")
    0:33: execution error: "http://python.org" doesn’t understand the “open location” message. (-1708)
    False

    >>> ### but this works
    >>> br = webbrowser.get("safari")
    >>> br.open("http://python.org")
True
msg293882 - (view) Author: Andrew Jaffe (Andrew.Jaffe) Date: 2017-05-17 19:53
A few more details:

 - I believe this worked correctly under previous macOS versions (but I don't currently have access to any such machines). 
 - This behaviour is identical under 3.6.1 and 2.7.13 (untested elsewhere)
 - Behaviour first noticed under Jupyter notebook -- see https://github.com/jupyter/notebook/issues/2438
msg293913 - (view) Author: Andrew Jaffe (Andrew.Jaffe) Date: 2017-05-18 08:30
The same behaviour also happens under Apple's system Python 2.7.10.

Perhaps this implies a macOS bug or deliberate behaviour change? (I couldn't find anything obviously appropriate in the list of security fixes for 10.12.5.)
msg293950 - (view) Author: Rudi Grams (Rudi Grams) Date: 2017-05-19 05:33
changing lines 594 and 623 in webbrowser.py (python 2.7.13) to avoid the broken 'open location' seems to solve the problem in idle .

script = 'do shell script "open %s"' % url.replace('"', '%22')
msg293953 - (view) Author: Andrew Jaffe (Andrew.Jaffe) Date: 2017-05-19 08:45
This seems to be a bug in the `osascript` application in the latest macOS 10.12.5:

$ osascript <<EOF
> open location "http://python.org"
> EOF
0:33: execution error: "http://python.org" doesn’t understand the “open location” message. (-1708)
msg294177 - (view) Author: Dariusz Smigiel (dasm) * Date: 2017-05-22 20:20
The same applies for latest build: 
Python 3.7.0a0 (heads/master:128641d17e, May 22 2017, 09:40:08)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin

I can try to work on that.
msg294186 - (view) Author: Dariusz Smigiel (dasm) * Date: 2017-05-22 21:27
Rudi, Andrew I missed your replaces.
This, indeed, looks like osascript bug. I don't think it's backward incompatible change, especially between 10.12.4 and 10.12.5 which would completely broke default behavior.
msg294194 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2017-05-22 22:13
We should check whether the osascript regression is fixed in the most recent 10.12.6 Developer Preview and, if not, open a RADAR (Apple bug report).
msg294239 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2017-05-23 08:28
The alternative to filing a RADAR is to just use the open command instead of osascript (basically what's suggested in msg293950 but directly using subprocess.check_call(["/usr/bin/open", ...]) instead of involving osascript).

For 3.7 it might be useful to drop usage of osascript altogether although that would result in some loss of functionality (/usr/bin/open cannot control if the URL should open in a new window or not).
msg294240 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2017-05-23 08:32
This indeed appears to be a bug in osascript, the scriptlet still works when using the AppleScript Editor application, which means the AppleScript environment itself and browser scripting support still work.
msg294241 - (view) Author: Andrew Jaffe (Andrew.Jaffe) Date: 2017-05-23 08:37
Yes, it's a weird bug. see http://www.andrewjaffe.net/blog/2017/05/python-bug-hunt.html for more of the story so far.

I have already filed a radar, and I hope this will get fixed at Apple, but it's a bug we need to live with for a while one way or the other.

(For what it's worth, among other things the current implementation relies on the officially deprecated os.popen() which has nothing to do with this problem but I guess this could be taken as an opportunity to change...)
msg294348 - (view) Author: Andrew Jaffe (Andrew.Jaffe) Date: 2017-05-24 11:53
I'll also note that my bug report (radar) has been marked as "DUPLICATE OF 31898264 (OPEN)". So Apple is aware of the bug, and possibly not completely ignoring it. However, the opacity of the system is such that there is no way to get any further information (even though we know the bug number).
msg294465 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2017-05-25 11:01
FWIW: The bug in osascript is still present in the current 10.12.6 beta (build 16G8c)
msg294865 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2017-05-31 18:33
Good news!  Apple appears to have fixed the osascript regression in the most recent macOS 10.12.6 public beta (version 2).  So I'm going to mark this issue as "pending fixed" until the official release of 10.12.6.
msg294981 - (view) Author: Kevin Ballard (Kevin Ballard) Date: 2017-06-02 04:26
There is a potential workaround that could be used so that way macOS 10.12.5 works. It turns out that, with osascript, if you catch the error and try again, it works.

$ osascript <<EOF
> try
> open location "http://apple.com"
> on error
> open location "http://apple.com"
> end try
> EOF
msg294984 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2017-06-02 06:05
Thanks for the suggestion but, by the time we have released the next maintenance updates for all actively maintained Python versions, 10.12.6 will have long been released and, once it has been, any need to support the broken 10.12.5 release is dead.
msg298709 - (view) Author: Andrew Jaffe (Andrew.Jaffe) Date: 2017-07-20 08:37
10.12.6 is out and the bug appears to be fixed...
History
Date User Action Args
2022-04-11 14:58:46adminsetgithub: 74577
2017-07-22 00:56:15ehusssetnosy: + ehuss
2017-07-20 08:37:37Andrew.Jaffesetstatus: pending -> closed
resolution: out of date -> third party
messages: + msg298709
2017-07-04 06:48:58glyphsetstatus: open -> pending
2017-07-04 06:48:40glyphsetstatus: pending -> open
nosy: + glyph
2017-06-02 06:05:49ned.deilysetstatus: open -> pending

messages: + msg294984
2017-06-02 04:26:50Kevin Ballardsetstatus: pending -> open
nosy: + Kevin Ballard
messages: + msg294981

2017-05-31 18:33:05ned.deilysetstatus: open -> pending
resolution: out of date
messages: + msg294865

stage: resolved
2017-05-26 20:34:05tgechosetnosy: + tgecho
2017-05-25 11:01:06ronaldoussorensetmessages: + msg294465
2017-05-24 11:53:08Andrew.Jaffesetmessages: + msg294348
2017-05-23 08:37:27Andrew.Jaffesetmessages: + msg294241
2017-05-23 08:32:13ronaldoussorensetmessages: + msg294240
2017-05-23 08:28:59ronaldoussorensetmessages: + msg294239
2017-05-22 22:13:52ned.deilysetmessages: + msg294194
2017-05-22 21:27:34dasmsetmessages: + msg294186
2017-05-22 20:20:39dasmsetnosy: + dasm

messages: + msg294177
versions: + Python 3.7
2017-05-22 20:06:52alangpiercesetnosy: + alangpierce
2017-05-19 08:45:53Andrew.Jaffesetmessages: + msg293953
2017-05-19 05:33:38Rudi Gramssetnosy: + Rudi Grams
messages: + msg293950
2017-05-18 08:30:25Andrew.Jaffesetmessages: + msg293913
2017-05-17 19:53:33Andrew.Jaffesettitle: default webbrowser not used on macOS Sierra 10.12.5 -> default webbrowser fails on macOS Sierra 10.12.5
2017-05-17 19:53:20Andrew.Jaffesetmessages: + msg293882
2017-05-17 19:50:01Andrew.Jaffesetmessages: + msg293881
2017-05-17 19:45:08Andrew.Jaffesettitle: default webbrowser macOS Sierra 10.12.5 -> default webbrowser not used on macOS Sierra 10.12.5
2017-05-17 19:44:16Andrew.Jaffecreate