Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

InfluxDBClientError while inserting None with DataFrameClient #726

Open
@msshroff

Description

@msshroff

Hi

I am using below Python 3.7.3 with influxdb 5.2.2
Trying to insert the DataFrame which has None or NaN
It fails with InfluxDBClientError: 400
It's generating Line Protocol data to be inserted with additional comma in field_set section

Python 3.7.3

$ pip show influxdb
Name: influxdb
Version: 5.2.2
Summary: InfluxDB client
Home-page: https://github.com/influxdb/influxdb-python
Author: None
Author-email: None
License: MIT License
Location: /opt/conda/lib/python3.7/site-packages
Requires: requests, six, pytz, python-dateutil
Required-by:

$ pip show pandas
Name: pandas
Version: 0.24.2
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: http://pandas.pydata.org
Author: None
Author-email: None
License: BSD
Location: /opt/conda/lib/python3.7/site-packages
Requires: python-dateutil, numpy, pytz
Required-by:

Code snippet to reproduce:

import pandas as pd
import numpy as np
from datetime import datetime, timedelta
import influxdb
import platform

print(f'Python Version: {platform.python_version()}')
print(f'Pandas Version: {pd.__version__}')
print(f'Library influxdb Version: {influxdb.__version__}')
      

date_today = datetime.now()
days = pd.date_range(date_today, date_today + timedelta(7), freq='D')

tag1 =  ['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8'] 
tag2 =  ['b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8'] 
tag3 =  ['c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8'] 

val1 = [1, 2, 3, 4, 5, 6, None, 8]
val2 = [10, 20, 30, 40, 50, 60, 70, 80]


df = pd.DataFrame({'time': days, 'tag1': tag1, 'tag2': tag2, 'tag3': tag3, 'val1': val1, 'val2': val2 })
df = df.set_index('time')
#print(df)

client = DataFrameClient(host='localhost', port=8086)
client.switch_database('MYDB)
inserted = client.write_points(df, 'TEST', tag_columns = ['tag1','tag2','tag3'] , field_columns = ['val1', 'val2'])

print(inserted)

Error stack:

Traceback (most recent call last):
  File "test.py", line 29, in <module>
    inserted = client.write_points(df, 'TEST', tag_columns = ['tag1','tag2','tag3'] , field_columns = ['val1', 'val2'])
  File "/opt/conda/lib/python3.7/site-packages/influxdb/_dataframe_client.py", line 138, in write_points
    protocol=protocol)
  File "/opt/conda/lib/python3.7/site-packages/influxdb/client.py", line 490, in write_points
    tags=tags, protocol=protocol)
  File "/opt/conda/lib/python3.7/site-packages/influxdb/client.py", line 551, in _write_points
    protocol=protocol
  File "/opt/conda/lib/python3.7/site-packages/influxdb/client.py", line 327, in write
    headers=headers
  File "/opt/conda/lib/python3.7/site-packages/influxdb/client.py", line 286, in request
    raise InfluxDBClientError(response.content, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: {"error":"partial write: unable to parse 'TEST,tag1=a7,tag2=b7,tag3=c7 ,val2=70i 1561467310365975040': invalid field format dropped=0"}

If I take the query with InfluxQL Line Protocol and try to rung it from influx CLI
I get same error.
If i remove the extra comma then it works

> insert TEST,tag1=a7,tag2=b7,tag3=c7 ,val2=70i 1561466427217511936
ERR: {"error":"unable to parse 'TEST,tag1=a7,tag2=b7,tag3=c7 ,val2=70i 1561466427217511936': invalid field format"}
> /* Notice reoving , (comma) before val2 */
> insert TEST,tag1=a7,tag2=b7,tag3=c7 val2=70i 1561466427217511936
>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions