Skip to content

how to write JSON to influxdb cloud using python #103

@Mogoatlhe

Description

@Mogoatlhe

Hi, i am having trouble sending data to my influxdb cloud instance in JSON format using Python 3.6.9.

body = Point("my_measurement").tag("location", "Prague").tag("location", "Tladistad").field("temperature", 25.3) write_api.write(bucket=buck, org=organisation, record=body)

the above works fine, but i want to use json (dictionary) and i also want have multiple tags and fields like below

json_body = [{"measurement": organisation, "tags":{"tag1":"tag1", "tag2": "tag2"}, "fields":{'field1':1, "field2":2}}] write_api.write(bucket=buck, org=organisation, record=json_body)

i get the error below

Traceback (most recent call last): File "initialize.py", line 12, in <module> write_api.write(bucket=buck, org=organisation, record=json_body) File "/home/moeketsi/.local/lib/python3.6/site-packages/influxdb_client/client/write_api.py", line 217, in write final_string = self._serialize(record, write_precision, **kwargs) File "/home/moeketsi/.local/lib/python3.6/site-packages/influxdb_client/client/write_api.py", line 263, in _serialize **kwargs) for item in record]) File "/home/moeketsi/.local/lib/python3.6/site-packages/influxdb_client/client/write_api.py", line 263, in <listcomp> **kwargs) for item in record]) File "/home/moeketsi/.local/lib/python3.6/site-packages/influxdb_client/client/write_api.py", line 253, in _serialize _result = self._serialize(Point.from_dict(record, write_precision=write_precision), File "/home/moeketsi/.local/lib/python3.6/site-packages/influxdb_client/client/write/point.py", line 37, in from_dict point.time(dictionary['time'], write_precision=write_precision) KeyError: 'time'

can you kindly assist, thank you (edited)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy