classification
Title: default webbrowser fails on macOS Sierra 10.12.5
Type: behavior Stage:
Components: Library (Lib), macOS Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Andrew.Jaffe, Rudi Grams, alangpierce, dasm, ned.deily, ronaldoussoren
Priority: normal Keywords:

Created on 2017-05-17 19:44 by Andrew.Jaffe, last changed 2017-05-24 11:53 by Andrew.Jaffe.

Messages (12)
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).
History
Date User Action Args
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