Connection Timeout Issue; Bokeh - during execution of export_png() function

After creating the bokeh figure object we are trying to EXPORT it to the local disk using the default bokeh function, i.e. export_png(). The charts are getting saved to the local disk for small datasets, but however, we are getting the following error for large datasets; Bokeh image created is “fig” as shown in the below error stack.

Traceback (most recent call last):
  File "X:\ApplicationX\lib\site-packages\urllib3\connectionpool.py", line 678, in urlopen
    chunked=chunked,
  File "X:\ApplicationX\lib\site-packages\urllib3\connectionpool.py", line 427, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "X:\ApplicationX\lib\site-packages\urllib3\connectionpool.py", line 422, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\<user_name>\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1344, in getresponse
    response.begin()
  File "C:\Users\<user_name>\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "C:\Users\<user_name>\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 267, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\<user_name>\AppData\Local\Programs\Python\Python37\lib\socket.py", line 591, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "X:\ApplicationX\services\bokeh_chart\xnx_chart.py", line 171, in xnx_chart
    path = export_png(fig, filename="X:\\image_store\")
  File "X:\ApplicationX\lib\site-packages\bokeh\io\export.py", line 97, in export_png
    image = get_screenshot_as_png(obj, height=height, width=width, driver=webdriver, timeout=20000)
  File "X:\ApplicationX\lib\site-packages\bokeh\io\export.py", line 219, in get_screenshot_as_png
    web_driver.get("file:///" + tmp.path)
  File "X:\ApplicationX\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "X:\ApplicationX\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
    response = self.command_executor.execute(driver_command, params)
  File "X:\ApplicationX\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
    return self._request(command_info[0], url, body=data)
  File "X:\ApplicationX\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 402, in _request
    resp = http.request(method, url, body=body, headers=headers)
  File "X:\ApplicationX\lib\site-packages\urllib3\request.py", line 80, in request
    method, url, fields=fields, headers=headers, **urlopen_kw
  File "X:\ApplicationX\lib\site-packages\urllib3\request.py", line 171, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "X:\ApplicationX\lib\site-packages\urllib3\poolmanager.py", line 336, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "X:\ApplicationX\lib\site-packages\urllib3\connectionpool.py", line 728, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "X:\ApplicationX\lib\site-packages\urllib3\util\retry.py", line 403, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "X:\ApplicationX\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
    raise value.with_traceback(tb)
  File "X:\ApplicationX\lib\site-packages\urllib3\connectionpool.py", line 678, in urlopen
    chunked=chunked,
  File "X:\ApplicationX\lib\site-packages\urllib3\connectionpool.py", line 427, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "X:\ApplicationX\lib\site-packages\urllib3\connectionpool.py", line 422, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\<user_name>\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1344, in getresponse
    response.begin()
  File "C:\Users\<user_name>\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "C:\Users\<user_name>\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 267, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\<user_name>\AppData\Local\Programs\Python\Python37\lib\socket.py", line 591, in readinto
    return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))```

StackOverflow: python - Connection Timeout Issue; Bokeh - during execution of export_png() function - Stack Overflow

The export_png function has a timeout parameter: bokeh.io — Bokeh 2.4.2 Documentation You could try configuring that to something larger.

Otherwise, those errors are coming from the webdriver, not from Bokeh itself, so it would require having a complete Minimal Reproducible Example that could be run directly to investigate.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.