Skip to content

Import data with namedtuple failed #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cvalentin-dkt opened this issue Oct 20, 2021 · 2 comments
Closed

Import data with namedtuple failed #351

cvalentin-dkt opened this issue Oct 20, 2021 · 2 comments
Labels
question Further information is requested wontfix This will not be worked on
Milestone

Comments

@cvalentin-dkt
Copy link

cvalentin-dkt commented Oct 20, 2021

Hello, I try to use exemple to import in my influxdb but i have an error and i don't found where is my error :/

My code :

from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS

class Daily(namedtuple('Daily', ['name', 'timestamp', 'pdl', 'value', 'measure_type'])):
  """
  Named structure - Daily
  """
  pass

with InfluxDBClient(url=influxdb_host, token=influxdb_token, org=influxdb_org) as client:
  write_api = client.write_api(write_options=SYNCHRONOUS)

daily = Daily(name="test", timestamp=datetime.utcnow(), pdl=pdl, value="25", measure_type="HP")
write_api.write(bucket=influxdb_bucket,
                        record=daily,
                        record_measurement_key="name",
                        record_time_key="timestamp",
                        record_tag_keys=["measure_type"],
                        record_field_keys=["value"])

Result :

 2021-10-20 11:50:53.945740 - INFO  : Connected to MQTT Broker!
 Traceback (most recent call last):
   File "/app/main.py", line 613, in <module>
     write_api.write(bucket=influxdb_bucket,
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/client/write_api.py", line 255, in write
     results = list(map(write_payload, payloads.items()))
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/client/write_api.py", line 253, in write_payload
     return self._post_write(_async_req, bucket, org, final_string, payload[0])
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/client/write_api.py", line 385, in _post_write
     return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/service/write_service.py", line 64, in post_write
     (data) = self.post_write_with_http_info(org, bucket, body, **kwargs)  # noqa: E501
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/service/write_service.py", line 168, in post_write_with_http_info
     return self.api_client.call_api(
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/api_client.py", line 341, in call_api
     return self.__call_api(resource_path, method,
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/api_client.py", line 171, in __call_api
     response_data = self.request(
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/api_client.py", line 386, in request
     return self.rest_client.POST(url,
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/rest.py", line 302, in POST
     return self.request("POST", url,
   File "/usr/local/lib/python3.9/site-packages/influxdb_client/rest.py", line 252, in request
     raise ApiException(http_resp=r)
 influxdb_client.rest.ApiException: (400)
 Reason: Bad Request
 HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Platform-Error-Code': 'invalid', 'Date': 'Wed, 20 Oct 2021 11:50:53 GMT', 'Content-Length': '197'})
 HTTP response body: {"code":"invalid","message":"unable to parse 'Sensor': missing fields\nunable to parse 'XXXXXXXXXXXXXXXX': missing fields\nunable to parse '25': missing fields\nunable to parse 'HP': missing fields"}

Have you idea ?

Docker image FROM : python:3.9.7-slim

@cvalentin-dkt cvalentin-dkt changed the title Import data with namedtuple Import data with namedtuple failed Oct 20, 2021
@bednar
Copy link
Contributor

bednar commented Oct 20, 2021

Hi @cvalentin-dkt,

thanks for using our client.

The supports for writing structured data (#330) will be publish in upcoming v1.22 release.

If you would like to use this feature before regular release, please install client via:

pip install git+https://github.com/influxdata/influxdb-client-python.git@master

Regards

@bednar bednar added question Further information is requested wontfix This will not be worked on labels Oct 20, 2021
@cvalentin-dkt
Copy link
Author

Hello @bednar ,

It's work !

Thx

@bednar bednar added this to the 1.22.0 milestone Oct 20, 2021
@bednar bednar closed this as completed Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants