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: When BROWSER is set on Mac webbrowser.register_standard_browsers doesn't work
Type: Stage: resolved
Components: macOS Versions: Python 3.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: fhackdroid, happycoder97, ned.deily, ograycode, ronaldoussoren, serhiy.storchaka, xtreak
Priority: normal Keywords:

Created on 2018-07-26 16:44 by ograycode, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (7)
msg322439 - (view) Author: Jason (ograycode) Date: 2018-07-26 16:44
Description: When BROWSER is set, webbrowser.get fails because register_standard_browsers throws an error.

Work around: You can still use `webbroswer._browsers[key][1].open(url)` to open a browser. 


Operating system: macOS High Sierra v10.13.6


Reproduction 1:

```
➜ BROWSER=lynx python3

Python 3.7.0 (default, Jul 23 2018, 20:22:55)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.get()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py", line 42, in get
    register_standard_browsers()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py", line 567, in register_standard_browsers
    cmd = _synthesize(cmdline, -1)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py", line 116, in _synthesize
    register(browser, None, controller, update_tryorder)
TypeError: register() takes from 2 to 3 positional arguments but 4 were given
```


Reproduction 2:

```
➜  BROWSER=lynx python3

Python 3.7.0 (default, Jul 23 2018, 20:22:55)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.register_standard_browsers()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py", line 567, in register_standard_browsers
    cmd = _synthesize(cmdline, -1)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py", line 116, in _synthesize
    register(browser, None, controller, update_tryorder)
TypeError: register() takes from 2 to 3 positional arguments but 4 were given
>>> webbrowser.lynx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'webbrowser' has no attribute 'lynx'
>>> webbrowser._browsers
{'macosx': [None, <webbrowser.MacOSXOSAScript object at 0x10df412e8>], 'chrome': [None, <webbrowser.MacOSXOSAScript object at 0x10df41358>], 'firefox': [None, <webbrowser.MacOSXOSAScript object at 0x10df485c0>], 'safari': [None, <webbrowser.MacOSXOSAScript object at 0x10df48b70>], 'lynx': [None, <webbrowser.GenericBrowser object at 0x10e014198>]}
>>> webbrowser._browsers['lynx'].open('http://google.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'open'
>>> webbrowser._browsers['lynx'][1].open('http://google.com') # This works
True
```
msg322443 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-26 17:49
I think it is fixed in issue31014.
msg322446 - (view) Author: Jason (ograycode) Date: 2018-07-26 19:55
Serhiy, I believe you are correct. I updated my local python and it passed.

However, I think there might be a bug with the implementation that doesn't
correctly respect the BROWSER preference. If I do:

```
➜  BROWSER=lynx python3

Python 3.7.0 (default, Jul 23 2018, 20:22:55)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.register_standard_browsers()
>>> webbrowser._tryorder
['MacOSX', 'chrome', 'firefox', 'safari', 'lynx', 'lynx']
>>> webbrowser._browsers
{'macosx': [None, <webbrowser.MacOSXOSAScript object at 0x101c142e8>],
'chrome': [None, <webbrowser.MacOSXOSAScript object at 0x101c14358>],
'firefox': [None, <webbrowser.MacOSXOSAScript object at 0x101d70c50>],
'safari': [None, <webbrowser.MacOSXOSAScript object at 0x101d70cc0>],
'lynx': [None, <webbrowser.GenericBrowser object at 0x101c82048>]}
```
Notice how the webbrowser._tryorder has two 'lynx' items and both of them
are last. If you look at the comment in the code, it says that it should be
prepended to _tryorder because it's the preferred browser. See
https://github.com/python/cpython/blob/56b29b6d6fa3eb32bb1533ee3f21b1e7135648a0/Lib/webbrowser.py#L563

If I change `cmd = _synthesize(cmdline, preferred=False)`, line 566, to
preferred=True then the output is like this:

```
>>> webbrowser._tryorder
['lynx', 'MacOSX', 'chrome', 'firefox', 'safari', 'lynx']
```

Which I believe is closer to being correct based upon the comments in the
code.

Am I wrong about this, and should I open up a new bug report for it?

Thanks.

On Thu, Jul 26, 2018 at 1:49 PM Serhiy Storchaka <report@bugs.python.org>
wrote:

>
> Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment:
>
> I think it is fixed in issue31014.
>
> ----------
> nosy: +serhiy.storchaka
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue34238>
> _______________________________________
>
msg323273 - (view) Author: Farzeen (happycoder97) Date: 2018-08-08 11:04
Arch Linux is also affected.
Steps to reproduce:
```
$ python
Python 3.7.0 (default, Jul 15 2018, 10:44:58) 
[GCC 8.1.1 20180531] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.get(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/webbrowser.py", line 42, in get
    register_standard_browsers()
  File "/usr/lib/python3.7/webbrowser.py", line 567, in register_standard_browsers
    cmd = _synthesize(cmdline, -1)
  File "/usr/lib/python3.7/webbrowser.py", line 116, in _synthesize
    register(browser, None, controller, update_tryorder)
TypeError: register() takes from 2 to 3 positional arguments but 4 were given
>>> 
```

Workaround:
```
$ env BROWSER='' python
Python 3.7.0 (default, Jul 15 2018, 10:44:58) 
[GCC 8.1.1 20180531] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.get(None)
<webbrowser.Mozilla object at 0x7f6bf8c75400>
>>> 
```
msg330885 - (view) Author: Farhaan Bukhsh (fhackdroid) * Date: 2018-12-02 15:30
Hey I would like to take this bug and work on it, can you please anyone guide me how do I proceed?
msg330898 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-12-02 19:41
> However, I think there might be a bug with the implementation that doesn't correctly respect the BROWSER preference. Notice how the webbrowser._tryorder has two 'lynx' items and both of them
are last. If you look at the comment in the code, it says that it should be prepended to _tryorder because it's the preferred browser

@ograycode Is this similar to issue35308 ?
msg332064 - (view) Author: Jason (ograycode) Date: 2018-12-18 14:39
Yes, it does. I haven't tried that code, but it looks similar to a fix I
implemented locally.

Jason O'Gray

On Sun, Dec 2, 2018 at 2:41 PM Karthikeyan Singaravelan <
report@bugs.python.org> wrote:

>
> Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:
>
> > However, I think there might be a bug with the implementation that
> doesn't correctly respect the BROWSER preference. Notice how the
> webbrowser._tryorder has two 'lynx' items and both of them
> are last. If you look at the comment in the code, it says that it should
> be prepended to _tryorder because it's the preferred browser
>
> @ograycode Is this similar to issue35308 ?
>
> ----------
> nosy: +xtreak
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue34238>
> _______________________________________
>
History
Date User Action Args
2022-04-11 14:59:03adminsetgithub: 78419
2018-12-19 09:25:41serhiy.storchakasetstatus: open -> closed
resolution: out of date
stage: resolved
2018-12-18 14:39:30ograycodesetmessages: + msg332064
2018-12-02 19:41:09xtreaksetnosy: + xtreak
messages: + msg330898
2018-12-02 15:30:26fhackdroidsetnosy: + fhackdroid
messages: + msg330885
2018-08-08 11:04:45happycoder97setnosy: + happycoder97
messages: + msg323273
2018-07-26 19:55:16ograycodesetmessages: + msg322446
2018-07-26 17:49:03serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg322443
2018-07-26 17:06:23ograycodesettype: crash ->
2018-07-26 16:44:44ograycodecreate