influxdata / influxdb-python

Python client for InfluxDB
MIT License
1.7k stars 522 forks source link

Cannot Insert dataframe with client 5.x #886

Open fadoming opened 3 years ago

fadoming commented 3 years ago

Hi there. Using influxdb client version 4.1.1, everything works like a charm but, I am having the following error when I try to insert data using any client of the brunch 5.x Data is a pandas DF I have used the server version: 1.8.5 and client 5.3.1 for this example

Here a piece of my code:

def insertDF(self, dbName, tbName, df,tags):

    self.connectDF(DB_INFLX_ADDRESS, DB_INFLX_PORT, DB_INFLX_USER, DB_INFLX_PASS, dbName)
    self.dbConnDF.write_points(df, tbName, tags=tags)

def main():
  rows=20000
  df = pd.DataFrame(data=list(range(rows)),
                    index=pd.date_range(start='2021-04-21', 
                                        periods=rows, 
                                        freq='H'), 
                    columns=['columnTag'])

  df['columnVal']=1

  tags = { 
          'count':df['columnTag'].to_list(),
         }

  inflxObjectD  = inflxDbClass()
  result      = inflxObjectD.insertDF(DB_INFLX_DBNAME, TABLE_NAME, df,tags) 

if __name__ == '__main__':
  main()

Steps to reproduce: List the minimal actions needed to reproduce the behavior.

  1. ...Run the code above with client 5.x and influxdb server 1.8.5

Expected behavior: DF to be inserted

Actual behavior:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 387, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1049, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.8/http/client.py", line 971, in send
    self.sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/fadoming/.local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3/dist-packages/six.py", line 702, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 387, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1049, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.8/http/client.py", line 971, in send
    self.sock.sendall(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "inf.py", line 88, in <module>
    main()
  File "inf.py", line 76, in main
    result      = inflxObjectD.insertDF(DB_INFLX_DBNAME, TABLE_NAME, df,tags) 
  File "inf.py", line 43, in insertDF
    self.dbConnDF.write_points(df, tbName, tags=tags)
  File "/home/fadoming/.local/lib/python3.8/site-packages/influxdb/_dataframe_client.py", line 135, in write_points
    super(DataFrameClient, self).write_points(
  File "/home/fadoming/.local/lib/python3.8/site-packages/influxdb/client.py", line 603, in write_points
    return self._write_points(points=points,
  File "/home/fadoming/.local/lib/python3.8/site-packages/influxdb/client.py", line 681, in _write_points
    self.write(
  File "/home/fadoming/.local/lib/python3.8/site-packages/influxdb/client.py", line 413, in write
    self.request(
  File "/home/fadoming/.local/lib/python3.8/site-packages/influxdb/client.py", line 332, in request
    response = self._session.request(
  File "/home/fadoming/.local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/fadoming/.local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/home/fadoming/.local/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))

Specifications: