influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
706 stars 185 forks source link

Can't send a custom timestamp to InfluxDB #645

Closed PiewTix closed 5 months ago

PiewTix commented 5 months ago

Specifications

Code sample to reproduce problem


time = local_time_to_unix(2024,5,2,4,1,1)

current_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')

p = Point("Solar_data").tag("Project", "777").tag("Installation", 1223).field("total_consumption", 0.5 ).time('1996-02-25T21:20:00.001001231Z')

write_api.write(bucket="humasol", record=p)

Expected behavior

I expect a record in InfluxDB with the provided timestamp from Python. With the provided code, no record gets added. Neither with the variable "time" With "current_time", a record gets added but it's the current time of the host PC when querying the record in the DB. So not the current time of adding the record through Python.

Actual behavior

Either InfluxDB takes the current time of the host PC at querying or no record gets added, depending on which timeformat is being used.

UPDATE

I tried to run the exact same code on a Linux host with an InfluxDBv2 database running on the same Linux host and it worked perfectly. So I suppose it's an issue specifically for a Windows (11) host? Is there a way I can fix it? I need it to work on a Windows 11 host as well...

bednar commented 5 months ago

Hi @PiewTix,

Thank you for choosing our client for your project.

To ensure we're on the same page, could you share how you're currently initializing the write_api? Based on your description, it sounds like your use case would benefit greatly from using the synchronous version of the API. This approach ensures that data writes are completed before the program proceeds, which might align well with your requirements.

Here's how you can initialize the write_api for synchronous operations:

write_api = client.write_api(write_options=SYNCHRONOUS)

This configuration directs the write_api to operate in a synchronous manner, providing a straightforward handling of write operations.

If you have any further questions or need additional assistance with your implementation, please don't hesitate to reach out.

Regards.

PiewTix commented 5 months ago

Hi @bednar ,

Thank you for your response.

Currently, this is indeed how I am initializing the write_api.

The InfluxDBv2 database is hosted on a Linux machine right now. I am still using a Linux machine (the same where the database is runnig) to execute my code, as it doesn't work on my Windows 11 machine yet.

bednar commented 5 months ago

@PiewTix, thanks for response.

Can you also check the debug output of the client? You can initialise the client with debug output by: InfluxDBClient("http://localhost:8099", token="my-token", debug=True).

PiewTix commented 5 months ago

Hi @bednar , Thanks for you response.

Where am I supposed to get the debug output? I don't see anything in my terminal in which I run the Python script.

Also, as I've decided to keep the Influx database on a Linux host, I don't see it as an issue anymore. Thank you for your time and help anyway!

bednar commented 5 months ago

The debug output should be in console output.