ConnectionRefusedError when trying to connect to influx

Hello,

I am trying to run some write group task using celery to write data inside influx.
My workers regularly encounters this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.10/http/client.py", line 975, in send
    self.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f9101b27460>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/celery/app/trace.py", line 451, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/celery/app/trace.py", line 734, in __protected_call__
    return self.run(*args, **kwargs)
  File "/app/timeseries/tasks/seed.py", line 248, in seed
    seed.service.insert_data(ts_fy.id, fy_df)
  File "/app/timeseries/services/timeserie.py", line 112, in insert_data
    self.ts_client.save_dataframe(timeserie.name, scient_df)
  File "/app/timeseries/client.py", line 84, in save_dataframe
    return self._wite_api.write(
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/client/write_api.py", line 371, in write
    results = list(map(write_payload, payloads.items()))
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/client/write_api.py", line 369, in write_payload
    return self._post_write(_async_req, bucket, org, final_string, payload[0])
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/client/write_api.py", line 517, in _post_write
    return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/service/write_service.py", line 63, in post_write
    (data) = self.post_write_with_http_info(org, bucket, body, **kwargs)  # noqa: E501
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/service/write_service.py", line 168, in post_write_with_http_info
    return self.api_client.call_api(
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/api_client.py", line 341, in call_api
    return self.__call_api(resource_path, method,
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/api_client.py", line 171, in __call_api
    response_data = self.request(
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/api_client.py", line 386, in request
    return self.rest_client.POST(url,
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/rest.py", line 304, in POST
    return self.request("POST", url,
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/rest.py", line 217, in request
    r = self.pool_manager.request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/request.py", line 78, in request
    return self.request_encode_body(
  File "/usr/local/lib/python3.10/site-packages/urllib3/request.py", line 170, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/poolmanager.py", line 376, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 813, in urlopen
    return self.urlopen(
  [Previous line repeated 2 more times]
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8086): Max retries exceeded with url: /api/v2/write?org=scient&bucket=scient&precision=ns (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9101b27460>: Failed to establish a new connection: [Errno 111] Connection refused'))

I have the same issue locally using docker and in my staging env using influxcloud from aws.

When i try to dig into the client code GitHub - influxdata/influxdb-client-python: InfluxDB 2.0 python client.
I see that my PoolManager is correctly setup to use a maxsize connection of 60 (default).
But when i debug i see that only 1 connection per pool is created and reused but when the client is trying to open a new one i hit this ConnectionRefusedError.

Am i missing something regarding concurrency writing using the python client ?

Thanks in advance,

Hi @MattMatt,

thanks for using our client.

It looks like that the InfluxDB doesn’t run on specified host and port. Can you check following example with your connection settings?

Regards