Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image export fails with Chromium 132 #253

Closed
mschoettle opened this issue Feb 14, 2025 · 3 comments
Closed

Image export fails with Chromium 132 #253

mschoettle opened this issue Feb 14, 2025 · 3 comments

Comments

@mschoettle
Copy link

mschoettle commented Feb 14, 2025

Somewhat related to #211, with alpine3.21 chromium v132 is now installed which fails with the following error:

Chromium 132.0.6834.83 Alpine Linux
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<Browser._open_async() done, defined at /usr/local/lib/python3.12/site-packages/choreographer/browser.py:246> exception=BrowserFailedError('The browser seemed to close immediately after starting. Perhaps adding debug_browser=True will help.')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/choreographer/browser.py", line 271, in _open_async
    await self.populate_targets()
  File "/usr/local/lib/python3.12/site-packages/choreographer/browser.py", line 603, in populate_targets
    response = await self.browser.send_command("Target.getTargets")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
choreographer.browser.BrowserClosedError: Command not completed because browser closed.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/choreographer/browser.py", line 274, in _open_async
    raise BrowserFailedError("The browser seemed to close immediately after starting. Perhaps adding debug_browser=True will help.") from e
choreographer.browser.BrowserFailedError: The browser seemed to close immediately after starting. Perhaps adding debug_browser=True will help.
Traceback (most recent call last):
  File "/app/test.py", line 4, in <module>
    fig.write_image("/output/figure.png")
  File "/usr/local/lib/python3.12/site-packages/plotly/basedatatypes.py", line 3827, in write_image
    return pio.write_image(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plotly/io/_kaleido.py", line 266, in write_image
    img_data = to_image(
               ^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plotly/io/_kaleido.py", line 143, in to_image
    img_bytes = scope.transform(
                ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/kaleido/scopes/plotly.py", line 235, in transform
    img = kaleido.to_image_block(spec, Path(self._tempfile.name).absolute(), self._topojson, self._mapbox_access_token, debug=debug, tmp_path=self._tmp_path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/kaleido/__init__.py", line 43, in to_image_block
    return asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug, tmp_path=tmp_path))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/kaleido/__init__.py", line 53, in to_image
    Browser(headless=True, debug=debug, debug_browser=debug, tmp_path=tmp_path) as browser,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
choreographer.browser.BrowserFailedError: Close() was called before the browser finished opening- maybe it crashed?

Kaleido: v1.0.0rc0
choreographer: 0.99.7

I pinned choreographer to 0.99.7 because with 1.0.3 I get:

Chromium 132.0.6834.83 Alpine Linux
Traceback (most recent call last):
  File "/app/test.py", line 4, in <module>
    fig.write_image("/output/figure.png")
  File "/usr/local/lib/python3.12/site-packages/plotly/basedatatypes.py", line 3827, in write_image
    return pio.write_image(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plotly/io/_kaleido.py", line 266, in write_image
    img_data = to_image(
               ^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plotly/io/_kaleido.py", line 132, in to_image
    raise ValueError(
ValueError: 
Image export using the "kaleido" engine requires the kaleido package,
which can be installed using pip:
    $ pip install -U kaleido

For that error I created the following issue: plotly/choreographer#218 but maybe it is a Plotly/kaleido issue?

@mschoettle
Copy link
Author

Updated my MRE repo: https://github.com/mschoettle/plotly-image-export-alpine

/cc @gvwilson @ayjayt

@breJcharAff
Copy link

I managed to avoid these two errors and make it work by using Kaleido 0.1.0.post1 with choreographer 0.99.7 and then changing cli.append("--headless=old") with cli.append("--headless") inside Lib/site-packages/choreographer/chrome_wrapper.py

@ayjayt
Copy link
Collaborator

ayjayt commented Feb 20, 2025

Hi @breJcharAff , we don't recommend pinning the old version. Kaleido 0.1.0.post1 doesn't use choreographer at all afaik. (That said, it's not a bad idea right now during the transition).

So @mschoettle, thanks so much for your patience, two things:

chromium version

The newer versions of Kaleido are going to, instead of automatically downloading the latest version of chromium, use a last known good version. This is a fix in choreographer v1.0.4- I'm not sure if Kaleido v1.0.0rc0 is compat w/ choreographer v1.*.*, but i think so, so I'll take a look at that error.

These "last known good versions" can be downloaded through the cli kaleido_get_chrome --help or through a function await kaleido.get_chrome()

These new versions of Kaleido (> Kaleido v1.0.0rc0) are not yet published on pypi and the API is slightly different.

Version Changes

Kaleido v1.0.0.rc0 was the old api with the new engine, but strategy has changed, and all Kaleido v1 will be new api new engine. We haven't pushed anything > rc0 yet because we're still working on documentation and because plotly needs to be aware of the new Kaleido API. You can use the new kaleido as a package by itself, but the integration with plotly and kaleido for the fig.write_image() shortcut is on-going.

Here is v1.0.0rc6 (current master branch), here is v1.0.0rc7. The api is slightly different and my personal reference is here: (for rc7) https://geopozo.github.io/Kaleido/

I know this is a lot. Once the documentation is done, v1 of Kaleido will 100% use the new API and engine.

@gvwilson I think this is what support is going to look like during the migration.

Closing, but open for discussion.

@ayjayt ayjayt closed this as completed Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants