diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index 606df721f33..a1cc2a61990 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -533,7 +533,8 @@ def write_html( # Write HTML string if path is not None: - path.write_text(html_str) + # To use a different file encoding, pass a file descriptor + path.write_text(html_str, "utf-8") else: file.write(html_str) diff --git a/packages/python/plotly/plotly/tests/test_io/test_pathlib.py b/packages/python/plotly/plotly/tests/test_io/test_pathlib.py index 48eab2bb9e5..092ffe6a9a6 100644 --- a/packages/python/plotly/plotly/tests/test_io/test_pathlib.py +++ b/packages/python/plotly/plotly/tests/test_io/test_pathlib.py @@ -40,7 +40,7 @@ def test_write_html(): mock_pathlib_path = Mock(spec=Path) pio.write_html(fig, mock_pathlib_path) mock_pathlib_path.write_text.assert_called_once() - (pl_html,) = mock_pathlib_path.write_text.call_args[0] + pl_html = mock_pathlib_path.write_text.call_args[0][0] assert replace_div_id(html) == replace_div_id(pl_html) # Test pio.write_html with a mock file descriptor