Kaleido fails to save image when used with mapbox
ramazanyagmur opened this issue · comments
Hi,
While working perfectly on charts, kaleido did not work for map export. I tried mapbox_style "light" , it also failed.
Showing the image on browser fig.show() works fine. But fails on saving the image to a static image file.
(Orca is not an alternative for me , because orca needs Xvfb and libgtk-3 , but the server OS is not in my control.)
The problem seems to occur when to_image(... transformation is being done.
sample code
import plotly.express as px
df = px.data.election()
geojson = px.data.election_geojson()
fig = px.choropleth_mapbox(df, geojson=geojson, color="Bergeron",
locations="district", featureidkey="properties.district",
center={"lat": 45.5517, "lon": -73.7073},
mapbox_style="carto-positron", zoom=9)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
fig.write_image("a.png",engine='kaleido')
The error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_1252675/723501538.py in <module>
10 fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
11 fig.show()
---> 12 fig.write_image("a.png",engine='kaleido')
/data01/01_anaconda/lib/python3.8/site-packages/plotly/basedatatypes.py in write_image(self, *args, **kwargs)
3827 import plotly.io as pio
3828
-> 3829 return pio.write_image(self, *args, **kwargs)
3830
3831 # Static helpers
/data01/01_anaconda/lib/python3.8/site-packages/plotly/io/_kaleido.py in write_image(fig, file, format, scale, width, height, validate, engine)
265 # -------------
266 # Do this first so we don't create a file if image conversion fails
--> 267 img_data = to_image(
268 fig,
269 format=format,
/data01/01_anaconda/lib/python3.8/site-packages/plotly/io/_kaleido.py in to_image(fig, format, width, height, scale, validate, engine)
142 # ---------------
143 fig_dict = validate_coerce_fig_to_dict(fig, validate)
--> 144 img_bytes = scope.transform(
145 fig_dict, format=format, width=width, height=height, scale=scale
146 )
/data01/01_anaconda/lib/python3.8/site-packages/kaleido/scopes/plotly.py in transform(self, figure, format, width, height, scale)
159 if code != 0:
160 message = response.get("message", None)
--> 161 raise ValueError(
162 "Transform failed with error code {code}: {message}".format(
163 code=code, message=message
ValueError: Transform failed with error code 525: Mapbox error.
Hi, I currently got a similar issue.
On one machine your minimal setup works fine and on another machine it throws the error code 525.
Currently I'm a bit clueless because the differences between the setups are really minimal.
The only bigger difference is that they are in different networks and might have different firewall configurations etc (don't know if that might influence kaleido).
Additionally on the machine there it's currently not working it was working roughly one week ago -> don't remember if I made some changes.
Both PCs are using Windows as OS.
working | not working | |
---|---|---|
Python | 3.9.5 | 3.9.13 |
kaleido | 0.2.1 | 0.2.1 |
numpy | 1.23.3 | 1.23.3 |
pandas | 1.5.0 | 1.5.0 |
pip | 22.2.2 | 22.2.2 |
plotly | 5.10.0 | 5.10.0 |
python-dateutil | 2.8.2 | 2.8.2 |
pytz | 2022.4 | 2022.4 |
setuptools | 56.0.0 | 58.1.0 |
six | 1.16.0 | 1.16.0 |
tenacity | 8.1.0 | 8.1.0 |
wheel | - | - |
Main difference in your environments seems to be Python version.
I am also adding version of modules you have mentioned.
not working (mine) | |
---|---|
Python | 3.8.12 |
kaleido | 0.2.1 |
numpy | 1.22.4 |
pandas | 1.3.4 |
pip | 22.2.2 |
plotly | 5.10.0 |
python-dateutil | 2.8.2 |
pytz | 2021.3 |
setuptools | 58.0.4 |
six | 1.16.0 |
tenacity | 8.0.1 |
wheel | 0.37.0 |
seems like my issue is really related to some proxy, dns or similar issues.
1st observation: if I just deactivate my internet connection on the working machine, then I get the same error 525.
2nd observation: if I export the figure as html and open that html file in the browser and load the tiles, then afterwards the write_image function works fine. It looks like the tiles might have been cached somewhere.
Retrieving a little bit more detailed error message would be quite helpful
I tried it on my personal pc where there is no internet access restriction. It worked just fine.
So ; I assume the problem is ; If fetching tiles for map fails, kaleido also fails.