Image export socket timeout


#1

Hi everyone, I’m pretty new to plotly and orca, please let me know if i’m missing something!

When I try to use the to_image() method, which returns an image as an encoded string I get this error:

ValueError:
The image request was rejected by the orca conversion utility
with the following error:
   522: client socket timeout

It is somewhat inconsistent. Sometimes there is no problem, sometimes it doesn’t work at all even if the image is exactly the same.

The chart I am trying to plot is a scattermapbox, with a polygon layer.

b0238d7-Living-clr_map

I am trying to do this from a controller function (I’m using web2py), to serve a view which contains the images.
The error is more likely to occur when I try the export from the controller. When I do it locally from a script it usually goes well (as you can see above).

Edit: (I’m using python 2.7)
Thanks


#2

Hi @federicosilvestri,

I wonder if you’re running into the problem discussed in https://github.com/plotly/orca/issues/164#issuecomment-444454487. The first time you export an image the orca server process is launched, and plotly.py attempts to communicate with it for up to 8 seconds. But if the server process takes longer than that to start up the first time, then the export fails.

We’re going to increase this time threshold in significantly in the next release (3.5.0), but in the meantime you can try to manually give the server process extra time to warm up by adding this to the top of your script/notebook:

import plotly
import time
plotly.io.orca.ensure_server()
time.sleep(10)  # Give orca server an extra 10 seconds to warm up

-Jon


#3

Hi @jmmease, thanks for your reply

I tried to give extra time but it didn’t work.

I run into this problem while generating a bunch of images: three are
regular scatterplots which have no problem, three are scattermapbox that give me this error.
I’ve tried manually launching the orca server on a port (8005) and setting
plotly.io.orca.config.port = 8005

this way the server is already launched and i get to see the messages it generates:

{"severity":"ERROR","textPayload":"525 - plotly.js error","labels":{"fid":null}}
{"severity":"INFO","httpRequest":{"requestMethod":"POST"},"labels":{"fid":null,"head":{"Content-Type":"image/png","Content-Length":27543},"processingTime":465.592489}}

The first log is the error thrown by orca when it tries to generate the map image, the second is relative to the regular scatterplot, which succeeds.
The same thing happens other two times with these scatter/map pairs.

I was thinking it was the json size I’m passing to the map to be a problem, but I’ve tried also with the example from https://plot.ly/python/scattermapbox/ and I get the same error.

I’ve also seen that the to_image() method is more likely to generate the error than write_image().

Any ideas on what sould I try?

Thank you very much for your time


#4

Hi @federicosilvestri, I hadn’t noticed last time that you were using scattermapbox traces. Have you configured orca with you mapbox access token? See https://plot.ly/python/orca-management/#config.

If not, give this a try:

plotly.io.orca.config.mapbox_access_token = 'your MAPBOX_TOKEN'
plotly.io.orca.save() # Persist config for future sessions

-Jon


#5

Hi @jmmease,
Yes, I had configured orca with my access token, in fact sometimes I was able to generate maps, but for some reason not anymore.

Could it be some limitations on number of export on the mapbox side?


#6

Hi @federicosilvestri,
I suppose it’s possible it has something to do with the mapbox side.

Let’s try to reproduce the issue using the orca command-line utility directly, and then open an issue with the orca repo (https://github.com/plotly/orca) if we can.

First output a JSON representation of a simple mapbox figure that reproduces the issue with

import plotly.io as pio
pio.write_json(fig, 'figure.json', pretty=True)

Then try exporting this JSON file to an image from the command line with

$ orca graph figure.json --mapbox-access-token YOUR_TOKEN -o figure.png

(you may need to replace orca with the full path to the orca executable depending on how your PATH is set up)

What happens for you in this case?
-Jon


#7

Hi @jmmease, sorry for the delay, here’s what’s happened when I tried what you suggested:
I’ve used the basic example of scattermapbox to ensure nothing else was influencing the output.

data = [
    go.Scattermapbox(
        lat=['45.5017'],
        lon=['-73.5673'],
        mode='markers',
        marker=dict(
            size=14
        ),
        text=['Montreal'],
    )
]

layout = go.Layout(
    autosize=True,
    hovermode='closest',
    mapbox=dict(
        accesstoken=MY_TOKEN,
        bearing=0,
        center=dict(
            lat=45,
            lon=-73
        ),
        pitch=0,
        zoom=5
    ),
)

fig = dict(data=data, layout=layout)

#write json with plotly.io
pio.write_json(fig, 'figure.json', pretty=True) 

Then in my terminal:

$ orca graph figure.json --mapbox-access-token MY_TOKEN -o figure.png --verbose

The output was this

gpu process crashed - false
          Chrome version 59.0.3071.115
          Electron version 1.8.4
renderer error - Uncaught TypeError: Failed to execute 'shaderSource' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLShader'.
          Chrome version 59.0.3071.115
          Electron version 1.8.4
renderer error - Uncaught TypeError: Failed to execute 'shaderSource' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLShader'.
          Chrome version 59.0.3071.115
          Electron version 1.8.4
renderer error - Uncaught TypeError: Failed to execute 'shaderSource' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLShader'.
          Chrome version 59.0.3071.115
          Electron version 1.8.4

Anyway I tried again in generating the maps from my controller and I was able to generate multiple images:
Here are two examples (with custom json layers)

download%20(4)

download%20(5)

But then it stopped working after generating ~20 images.

Thanks again for your time
-Federico


#8

Hi @federicosilvestri,

I think the next step is to open an issue with the orca project and see if anyone can reproduce the issue (https://github.com/plotly/orca/issues)? Just include and include the example JSON file produced by your exaple and the console error messages you’re seeing.

Thanks!
-Jon


#9

Hi @jmmease, I’ll open an issue there and see what they can do

Thanks!
Federico