Plotly - orca ConnectionRefusedError

My example :

import plotly
plotly.version

from plotly.offline import iplot, init_notebook_mode
import plotly.graph_objs as go
import plotly.io as pio

import os
import numpy as np

init_notebook_mode(connected=True)

N = 100
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
sz = np.random.rand(N)*30

fig = go.Figure()
fig.add_scatter(x=x,
y=y,
mode=‘markers’,
marker={‘size’: sz,
‘color’: colors,
‘opacity’: 0.6,
‘colorscale’: ‘Viridis’
});
iplot(fig)

if not os.path.exists(‘images’):
os.mkdir(‘images’)

pio.write_image(fig, ‘images/fig1.png’)


only works on a single user, it is curious because it is with the user that I executed it first.
I installed orca, plotly (the installation is from a docker, everything installed globally, pip install and so on) as it appears on the official page, orca --help in the terminal works for me, without any error.
If I do it in that user if I execute the code correctly, but if I execute it in any other, it does not work and I get the following error :


ConnectionRefusedError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/urllib3/connection.py in _new_conn(self)
170 conn = connection.create_connection(
–> 171 (self._dns_host, self.port), self.timeout, **extra_kw)
172

/opt/conda/lib/python3.6/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
78 if err is not None:
—> 79 raise err
80

/opt/conda/lib/python3.6/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
68 sock.bind(source_address)
—> 69 sock.connect(sa)
70 return sock

ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

NewConnectionError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
599 body=body, headers=headers,
–> 600 chunked=chunked)
601

/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
353 else:
–> 354 conn.request(method, url, **httplib_request_kw)
355

/opt/conda/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked)
1238 “”“Send a complete request to the server.”""
-> 1239 self._send_request(method, url, body, headers, encode_chunked)
1240

/opt/conda/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1284 body = _encode(body, ‘body’)
-> 1285 self.endheaders(body, encode_chunked=encode_chunked)
1286

/opt/conda/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked)
1233 raise CannotSendHeader()
-> 1234 self._send_output(message_body, encode_chunked=encode_chunked)
1235

/opt/conda/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked)
1025 del self._buffer[:]
-> 1026 self.send(msg)
1027

/opt/conda/lib/python3.6/http/client.py in send(self, data)
963 if self.auto_open:
–> 964 self.connect()
965 else:

/opt/conda/lib/python3.6/site-packages/urllib3/connection.py in connect(self)
195 def connect(self):
–> 196 conn = self._new_conn()
197 self._prepare_conn(conn)

/opt/conda/lib/python3.6/site-packages/urllib3/connection.py in _new_conn(self)
179 raise NewConnectionError(
–> 180 self, “Failed to establish a new connection: %s” % e)
181

NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f465ce420b8>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

MaxRetryError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
444 retries=self.max_retries,
–> 445 timeout=timeout
446 )

/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
637 retries = retries.increment(method, url, error=e, _pool=self,
–> 638 _stacktrace=sys.exc_info()[2])
639 retries.sleep()

/opt/conda/lib/python3.6/site-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
397 if new_retry.is_exhausted():
–> 398 raise MaxRetryError(_pool, url, error or ResponseError(cause))
399

MaxRetryError: HTTPConnectionPool(host=‘localhost’, port=36785): Max retries exceeded with url: / (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f465ce420b8>: Failed to establish a new connection: [Errno 111] Connection refused’,))

During handling of the above exception, another exception occurred:

ConnectionError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/plotly/io/_orca.py in to_image(fig, format, width, height, scale, validate)
1324 width=width,
-> 1325 height=height)
1326 except OSError as err:

/opt/conda/lib/python3.6/site-packages/retrying.py in wrapped_f(*args, **kw)
48 def wrapped_f(*args, **kw):
—> 49 return Retrying(*dargs, **dkw).call(f, *args, **kw)
50

/opt/conda/lib/python3.6/site-packages/retrying.py in call(self, fn, *args, **kwargs)
211 # get() on an attempt with an exception should cause it to be raised, but raise just in case
–> 212 raise attempt.get()
213 else:

/opt/conda/lib/python3.6/site-packages/retrying.py in get(self, wrap_exception)
246 else:
–> 247 six.reraise(self.value[0], self.value[1], self.value[2])
248 else:

/opt/conda/lib/python3.6/site-packages/six.py in reraise(tp, value, tb)
692 raise value.with_traceback(tb)
–> 693 raise value
694 finally:

/opt/conda/lib/python3.6/site-packages/retrying.py in call(self, fn, *args, **kwargs)
199 try:
–> 200 attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
201 except:

/opt/conda/lib/python3.6/site-packages/plotly/io/_orca.py in request_image_with_retrying(**kwargs)
1231 json_str = json.dumps(request_params, cls=plotly.utils.PlotlyJSONEncoder)
-> 1232 response = requests.post(server_url + ‘/’, data=json_str)
1233 return response

/opt/conda/lib/python3.6/site-packages/requests/api.py in post(url, data, json, **kwargs)
111
–> 112 return request(‘post’, url, data=data, json=json, **kwargs)
113

/opt/conda/lib/python3.6/site-packages/requests/api.py in request(method, url, **kwargs)
57 with sessions.Session() as session:
—> 58 return session.request(method=method, url=url, **kwargs)
59

/opt/conda/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
511 send_kwargs.update(settings)
–> 512 resp = self.send(prep, **send_kwargs)
513

/opt/conda/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs)
621 # Send the request
–> 622 r = adapter.send(request, **kwargs)
623

/opt/conda/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
512
–> 513 raise ConnectionError(e, request=request)
514

ConnectionError: HTTPConnectionPool(host=‘localhost’, port=36785): Max retries exceeded with url: / (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f465ce420b8>: Failed to establish a new connection: [Errno 111] Connection refused’,))

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
in
49
50
—> 51 pio.write_image(fig, ‘images/fig1.png’)
52
53

/opt/conda/lib/python3.6/site-packages/plotly/io/_orca.py in write_image(fig, file, format, scale, width, height, validate)
1510 width=width,
1511 height=height,
-> 1512 validate=validate)
1513
1514 # Open file

/opt/conda/lib/python3.6/site-packages/plotly/io/_orca.py in to_image(fig, format, width, height, scale, validate)
1340
1341 {info}
-> 1342 “”".format(info=status_str))
1343 else:
1344 # Reset the status so that if the user tries again, we’ll try to

ValueError:
For some reason plotly.py was unable to communicate with the
local orca server process, even though the server process seems to be running.

Please review the process and connection information below:

orca status

state: running
executable: /opt/conda/bin/orca
version: 1.2.1
port: 36785
pid: 2935
command: ['/opt/conda/bin/orca', 'serve', '-p', '36785', '--plotly', '/opt/conda/lib/python3.6/site-packages/plotly/package_data/plotly.min.js', '--graph-only', '--mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js']

I don’t understand why it works for one user and not for the others.
Thanks.

Hi @claudia,

I don’t have any initial ideas of what might be causing this. Is everything you’re doing running inside the docker container? Are there any firewall-style settings that might be restricting open ports? You could try launching orca from the command line with the --debug flag and see if there is any difference in the output between doing so with the working verse non-working users. For your situation above, run this command from the terminal.

$ /opt/conda/bin/orca serve -p 36785 --plotly /opt/conda/lib/python3.6/site-packages/plotly/package_data/plotly.min.js --graph-only --mathjax https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js --debug

-Jon

Thank you for answering,
I have executed the command line that you gave me with the user that allows me and with the one that doesn’t, and with the user that doesn’t allow me I get the following error:

Spinning up server with pid: 1197
{“severity”:“ERROR”,“textPayload”:“Error: EACCES: permission denied, open ‘/tmp/orca-build/index-42a834e5-1946-4aba-9258-f3740bf6e17e.html’”}

How can it be solved? thank you very much

Thank you for answering,
I have executed the command line that you gave me with the user that allows me and with the one that doesn’t, and with the user that doesn’t allow me I get the following error:

Spinning up server with pid: 1197
{“severity”:“ERROR”,“textPayload”:“Error: EACCES: permission denied, open ‘/tmp/orca-build/index-42a834e5-1946-4aba-9258-f3740bf6e17e.html’”}

How can it be solved? thank you very much

Hi @claudia,

That’s a helpful clue! Perhaps there is some issue with the permission on your /tmp directory (or an issue with how orca creates the /tmp/orca-build directory).

Could you try opening up the permissions on /tmp/orca-build. with chmod 777 /tmp/orca-build?

-Jon

yes, thank you the answer was clear but I do not understand why in the /tmp/ is saved or run when installing, is there any way to change that?
Thanks

Does that mean that changing the permissions allowed image export to work properly?

This is a file that orca uses as the entry point for the electron application. No, there’s no way to change that. It looks like there is something we might be able to do about the permission on the orca-build directory. If you confirm that changing those permissions manually removes the error then I’ll open an issue with the orca project to discuss what we can do in orca itself.

-Jon

Yes, it works. Thank you so much for the time and explanation.

Looks like there was already an issue on this at https://github.com/plotly/orca/issues/140.
-Jon

Yes, in the end I had to touch the ‘/opt/conda/pkgs/plotly-orca-1.2.1-1/lib/orca_app/resources/app/src/util/create-index.js’ so that every time a new user used it, the /tmp/orca-build/ folder is cleaned and the permissions are set to 777. I modified and added:

try {
  fs.mkdirSync(PATH_TO_BUILD)
  fs.chmodSync(PATH_TO_BUILD, 0777)
} catch (e) {}
try{
  fs.readdir(PATH_TO_BUILD, (err, files) => {
  if (err) throw err

  for (const file of files) {
    fs.unlink(path.join(PATH_TO_BUILD, file), err => {
      if (err) throw err
    })
  }
})
} catch (e) {}

Thanks for sharing your solution @claudia!

Changing the permission to 777 after creating /tmp/orca-build makes sense to me, but did you need to manually delete any existing files in the directory? I would have thought that the permission change would have been enough, and I’m wondering if deleting the existing tmp files would cause a problem if multiple users are using orca at the same time on the system.

-Jon

The directory is created but begins to fill with other users to use it, in my case, what I do is that every time you create one is erasing the contents of that folder, but for later there may be problem of space.

I’m seeing this error as well, but it doesn’t appear to be the permissions issue. When I run

! /opt/conda/bin/orca serve -p 36785 --plotly /opt/conda/lib/python3.6/site-packages/plotly/package_data/plotly.min.js --graph-only --mathjax https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js --debug

The output is:

Spinning up server with pid: 496
created index-43f6046b-2e91-4648-9979-0244fe75b594.html for plotly-graph component
{“severity”:“ERROR”,“textPayload”:“gpu process crashed - false”}
{“severity”:“ERROR”,“textPayload”:“gpu process crashed - false”}
{“severity”:“ERROR”,“textPayload”:“gpu process crashed - false”}
{“severity”:“ERROR”,“textPayload”:“gpu process crashed - false”}
{“severity”:“ERROR”,“textPayload”:“gpu process crashed - false”}
{“severity”:“ERROR”,“textPayload”:“gpu process crashed - false”}
Listening on port 36785 after a 7151.992313 ms bootup
Open routes: /

I’m running orca in a Jupyter notebook via a Docker container managed by Jupyterhub. The container is based on miniconda. Let me know what other details are needed. Thanks!

If I run the following, the PDF is produced without issues.

(base) root@565ed901eaf0:~# orca graph test.json --format pdf -o test.pdf --verbose
gpu process crashed - false
Chrome version 59.0.3071.115
Electron version 1.8.4
gpu process crashed - false
Chrome version 59.0.3071.115
Electron version 1.8.4
gpu process crashed - false
Chrome version 59.0.3071.115
Electron version 1.8.4
gpu process crashed - false
Chrome version 59.0.3071.115
Electron version 1.8.4
gpu process crashed - false
Chrome version 59.0.3071.115
Electron version 1.8.4
gpu process crashed - false
Chrome version 59.0.3071.115
Electron version 1.8.4
exported test, in 635.462876 ms

done with code 0 in 636.50 ms - all task(s) completed

I fixed this issue by adding the -a parameter to the xvfb-run command in my Dockerfile and rebuilding the docker image:

RUN echo "#!/bin/bash\nxvfb-run -a /opt/conda/lib/orca_app/orca \"\$@\" " > /opt/conda/bin/orca && \ chmod +x /opt/conda/bin/orca

Hi @argoneus, thanks for sharing your solution!
-Jon