Skip to content

write_html fails with latest plotly.min.js version 2.17.1 #4019

Closed
@johannesloibl

Description

@johannesloibl

The latest plotly.min.js version 2.17.1 contains special characters which are not supported by the Windows cp1252 default codec.
E.g. \u25c4 (https://www.fileformat.info/info/unicode/char/25c4/index.htm).

Reproducible example (Win 10, 64bit, plotly 5.12):

import plotly
print(plotly.__version__)

import plotly.express as px

fig =px.scatter(x=range(10), y=range(10))
fig.write_html("file.html", include_plotlyjs="directory")

This produces following error:

Traceback (most recent call last):
  File "C:\Users\...\scratches\scratch_2.py", line 7, in <module>
    fig.write_html("file.html", include_plotlyjs="directory")
  File "C:\git\...\.tox\codecov\lib\site-packages\plotly\basedatatypes.py", line 3700, in write_html
    return pio.write_html(self, *args, **kwargs)
  File "C:\git\...\.tox\codecov\lib\site-packages\plotly\io\_html.py", line 545, in write_html
    bundle_path.write_text(get_plotlyjs())
  File "C:\Python39\lib\pathlib.py", line 1286, in write_text
    return f.write(data)
  File "C:\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u25c4' in position 276182: character maps to <undefined>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions