Skip to content

ValueError: Transform failed with error code 1: Failed to serialize document: Uncaught #41

Closed

Description

@wdecoster

Related issue: wdecoster/NanoPlot#207

A user reported an error coming from kaleido, the relevant part of the traceback is below:

    f.write(scope.transform(self.fig, format="png"))
  File "/home/user/.local/lib/python3.8/site-packages/kaleido/scopes/plotly.py", line 110, in transform
    raise ValueError(
ValueError: Transform failed with error code 1: Failed to serialize document: Uncaught

The code is:

scope = PlotlyScope()
with open('output.png'), "wb") as f:
    f.write(scope.transform(fig, format="png"))

It could be that the image is rather large, would that explain the problem? What can I do to debug?

Thanks,
Wouter

Activity

  1. jonmmease commented on Sep 17, 2020

    @jonmmease
    Collaborator

    Hi @wdecoster, thanks for the report. There is an open issue for figures that are "too large" (#19) but that results in a particular error that's different that what you're seeing.

    My first question would be whether this happens with even small simple figures.


    Here's one guess. When you build the PlotlyScope using the default constructor, Kaleido uses an online CDN location for the plotly.js bundle. So if the user doesn't have internet access (or is behind a proxy/firewall) then this kind of error could occur.

    The plotlyjs argument/property to PlotlyScope can be used to point Kaleido to a local plotly.js bundle, which is what plotly.py does. If you're comfortable requiring plotly >= 4.9, then I would actually recommend letting plotly.py take care of interacting with kaleido, replacing what you have with

    import plotly.io as pio
    pio.write_image(fig, "output.png", engine="kaleido")
    

    If you need to support older versions of plotly.py, then you could copy the kaleido initialization logic from

    https://github.com/plotly/plotly.py/blob/8289eb1c85125e147c4ce14b56272ed50b99ef20/packages/python/plotly/plotly/io/_kaleido.py#L9-L17

    which will configure the PlotlyScope to use the plotly.js bundle that is included with plotly.py.

  2. wdecoster commented on Sep 18, 2020

    @wdecoster
    Author

    Great, thanks for the pointers. I'll make some changes and test that. It seems indeed to be the case that the user doesn't have internet access on this machine.

  3. nehaljwani commented on Oct 1, 2020

    @nehaljwani

    I hit the same issue and copying the init logic worked in my case.

  4. jonmmease commented on Oct 1, 2020

    @jonmmease
    Collaborator

    @wdecoster, have you had a chance to try this?

  5. wdecoster commented on Oct 6, 2020

    @wdecoster
    Author

    Sorry for the lack of feedback, I hope to get back to this next week.

  6. wdecoster commented on Oct 9, 2020

    @wdecoster
    Author

    I made the changes you suggested (pio.write_image(fig, "output.png", engine="kaleido")), and at least a test where I unplugged my ethernet cable worked with the changes (but not without). I expect this also to fix the problem for the user who initially reported the error.

    Thanks!

  7. jonmmease commented on Oct 9, 2020

    @jonmmease
    Collaborator

    Great! Just make sure to update your minimum plotly.py version requirement to plotly>=4.9.0.

    edit: Never mind, I see that you did in wdecoster/NanoPlot@9c840b7

  8. wdecoster commented on Oct 9, 2020

    @wdecoster
    Author

    Took care of that, but thanks for the warning ;-)

  9. added a commit that references this issue on Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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