Maximum Recursion Depth Exceeded Error in Python WebSocket Client Writing to InfluxDB

Hello everyone,

I am running a WebSocket client on a cloud instance that receives messages from a WebSocket data provider and writes them into an InfluxDB container hosted locally on the same cloud instance. The system ran fine for about two days, but then it started continuously giving me a maximum recursion depth error.

InfluxDBv2 OSS
Docker Image : influxdb:latest
Python Client v1.44.0

Error Logs:

ERROR - error from callback <function on_message at 0x7f77fbe9e430>: maximum recursion depth exceeded in comparison
websocket-client_1      | ERROR - Error: maximum recursion depth exceeded in comparison
websocket-client_1      | ERROR - Failed to write message 4682252 to influxDB: maximum recursion depth exceeded in comparison
websocket-client_1      | ERROR - Data: \g:1-2-1657,s:rORBCOMM000,c:1719759229*56\!AIVDM,2,1,7,A,53pr=Q81q7rm=4iD000tAU<0000000000000000l1@I364u80=4Slm3hjjh0,0*22
websocket-client_1      | ERROR - Traceback (most recent call last):
websocket-client_1      |   File "/app/src/utils/", line 31, in store_to_influxdb
websocket-client_1      |     write_api.write(bucket="nmea_data", record=point)
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/client/", line 381, in write
websocket-client_1      |     results = list(map(write_payload, payloads.items()))
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/client/", line 379, in write_payload
websocket-client_1      |     return self._post_write(_async_req, bucket, org, final_string, payload[0])
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/client/", line 516, in _post_write
websocket-client_1      |     return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/service/", line 60, in post_write
websocket-client_1      |     (data) = self.post_write_with_http_info(org, bucket, body, **kwargs)  # noqa: E501
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/service/", line 90, in post_write_with_http_info
websocket-client_1      |     return self.api_client.call_api(
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/_sync/", line 343, in call_api
websocket-client_1      |     return self.__call_api(resource_path, method,
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/_sync/", line 173, in __call_api
websocket-client_1      |     response_data = self.request(
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/_sync/", line 388, in request
websocket-client_1      |     return self.rest_client.POST(url,
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/_sync/", line 311, in POST
websocket-client_1      |     return self.request("POST", url,
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/influxdb_client/_sync/", line 220, in request
websocket-client_1      |     r = self.pool_manager.request(
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/urllib3/", line 144, in request
websocket-client_1      |     return self.request_encode_body(
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/urllib3/", line 255, in request_encode_body
websocket-client_1      |     extra_kw: dict[str, typing.Any] = {"headers": HTTPHeaderDict(headers)}
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/urllib3/", line 249, in __init__
websocket-client_1      |     self.extend(headers)
websocket-client_1      |   File "/usr/local/lib/python3.9/site-packages/urllib3/", line 351, in extend
websocket-client_1      |     elif isinstance(other, typing.Mapping):
websocket-client_1      |   File "/usr/local/lib/python3.9/", line 720, in __instancecheck__
websocket-client_1      |     return self.__subclasscheck__(type(obj))
websocket-client_1      |   File "/usr/local/lib/python3.9/", line 852, in __subclasscheck__
websocket-client_1      |     return issubclass(cls, self.__origin__)
websocket-client_1      |   File "/usr/local/lib/python3.9/", line 123, in __subclasscheck__
websocket-client_1      |     return _abc_subclasscheck(cls, subclass)
websocket-client_1      | RecursionError: maximum recursion depth exceeded in comparison
websocket-client_1      | 
websocket-client_1      | ERROR - error from callback <function on_message at 0x7f77fbe9e430>: maximum recursion depth exceeded in comparison

My write Funcion:

def store_to_influxdb(data, count):
        point = (
            .time(datetime.utcnow(), influxdb_client.WritePrecision.NS)
            .field("data", data)

        write_api.write(bucket="nmea_data", record=point)
        if count % 1000 == 0:
  "Message {count} stored to InfluxDB successfully")
    except Exception as e:
        logger.error(f"Failed to write message {count} to influxDB: {e}")
        logger.error(f"Data: {data}")

One quick thing you can try is to increase to recursion limit and see if that gets rid of the problem by adding something like this at the top: sys.setrecursionlimit(1500). Ref: sys — System-specific parameters and functions — Python 3.12.4 documentation.

Otherwise it seems there might be a bug in the client sdk and you can report it on GitHub (they are usually pretty quick to respond). If you report the bug make sure to provide example “data” & “count” value that you used so they can try to reproduce it.