#######################
from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS
from datetime import datetime
import json
Hi @bednar
Thank you for your response.
I used the code you suggested, but the database seems to be empty at first. Later i pulled new data into the weather.json file and ran the script. it showed the following error.
Traceback (most recent call last):
File “c:\Users\akash\internship\database.py”, line 36, in
client.write_api(write_options=SYNCHRONOUS).write(bucket=bucket,
File “C:\Users\akash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\influxdb_client\client\write_api.py”, line 374, in write
results = list(map(write_payload, payloads.items()))
File “C:\Users\akash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\influxdb_client\client\write_api.py”, line 372, in write_payload
return self._post_write(_async_req, bucket, org, final_string, payload[0])
File “C:\Users\akash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\influxdb_client\client\write_api.py”, line 483, in _post_write
return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
File "C:\Users\akash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\influxdb_client\service\write_se File “C:\Users\akash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\influxdb_client_sync\api_client.py”, line 388, in request
return self.rest_client.POST(url, File “C:\Users\akash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\influxdb_client_sync\rest.py”, line 307, in POST
return self.request(“POST”, url, File “C:\Users\akash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\influxdb_client_sync\rest.py”, line 257, in request
raise ApiException(http_resp=r)influxdb_client.rest.ApiException: (422)
Reason: Unprocessable Entity
HTTP response headers: HTTPHeaderDict({‘Content-Type’: ‘application/json; charset=utf-8’, ‘X-Influxdb-Build’: ‘OSS’, ‘X-Influxdb-Version’: ‘v2.4.0’, ‘X-Platform-Error-Code’: ‘unprocessable entity’, ‘Date’: ‘Wed, 12 Oct 2022 11:41:44 GMT’, ‘Content-Length’: ‘224’})
HTTP response body: {“code”:“unprocessable entity”,“message”:“failure writing points to database: partial write: field type conflict: input field "windSpeed" on measurement "weather" is type float, already exists as type integer dropped=1”}
Hi @bednar
i managed to change the data in the weather.json into the relevevant data type and it takes in the data when the data type are matched
“humidity”: 74,
“temperature”: 19.5,
“windSpeed”: 5
but fails to update the database when the data changes to
“humidity”: 74,
“temperature”: 19.5,
“windSpeed”: 5.5