Skip to content

Commit

Permalink
improve browser error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaskruchten committed Jul 21, 2021
1 parent 2c2dd6a commit a547e37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed
- Fixed regression introduced in version 5.0.0 where pandas/numpy arrays with `dtype` of Object were being converted to `list` values when added to a Figure ([#3292](https://github.com/plotly/plotly.py/issues/3292), [#3293](https://github.com/plotly/plotly.py/pull/3293))
- Better detection of Chrome and Chromium browsers in the Renderers framework, especially on Linux ([#3278](https://github.com/plotly/plotly.py/pull/3278)) with thanks to [@c-chaitanya](https://github.com/c-chaitanya) for the contribution

## [5.1.0] - 2021-06-28

Expand Down
26 changes: 16 additions & 10 deletions packages/python/plotly/plotly/io/_base_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,21 @@ def open_html_in_browser(html, using=None, new=0, autoraise=True):
if isinstance(html, six.string_types):
html = html.encode("utf8")

if isinstance(using, tuple):
try:
using = [i for i in webbrowser._browsers.keys() if i in using][0]
except IndexError:
raise ValueError(
"""
Unable to find the given browser.
Try one among the following 'chrome', 'chromium', 'firefox' or 'default' """
)
browser = None

if using is None:
browser = webbrowser.get()
else:
if not isinstance(using, tuple):
using = (using,)
for browser_key in using:
try:
browser = webbrowser.get(browser_key)
except webbrowser.Error:
pass

if browser is None:
raise ValueError("Can't locate a browser with key in " + str(using))

class OneShotRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
Expand All @@ -694,7 +700,7 @@ def log_message(self, format, *args):
pass

server = HTTPServer(("127.0.0.1", 0), OneShotRequestHandler)
webbrowser.get(using).open(
browser.open(
"http://127.0.0.1:%s" % server.server_port, new=new, autoraise=autoraise
)

Expand Down

0 comments on commit a547e37

Please sign in to comment.