influxdata / influxdb-python

Python client for InfluxDB
MIT License
1.69k stars 520 forks source link

Can't write point with numerical and string field keys #793

Open mattcarp12 opened 4 years ago

mattcarp12 commented 4 years ago
# python
Python 3.8.2 (default, Feb 26 2020, 15:17:37) 
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> foo = {1:2, 3:4, "foo":"bar"}
>>> from influxdb import InfluxDBClient
>>> idb = InfluxDBClient(
...     host="influxdb",
...     port=8086,
...     username="root",
...     password="root",
...     database="test",
... )
>>> point = [{"measurement": "test", "fields": foo}]
>>> idb.write_points(point)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 525, in write_points
    return self._write_points(points=points,
  File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 594, in _write_points
    self.write(
  File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 331, in write
    data = make_lines(data, precision).encode('utf-8')
  File "/usr/local/lib/python3.8/site-packages/influxdb/line_protocol.py", line 156, in make_lines
    for field_key, field_value in sorted(iteritems(point['fields'])):
TypeError: '<' not supported between instances of 'str' and 'int'
mattcarp12 commented 4 years ago

However {"1":2, "3":4, "foo":"bar"} and {1:2, 3:4} both work.

sebito91 commented 4 years ago

Hmm, that's indeed a bug. Thanks for reporting this @mattcarp12, I'll take a look into this for the v5.3.1 point release.