Custom timestamp from Influxdb-client Python to InfluxDBv2 not working

26 views Asked by At

I can't seem to send a timestamp to InfluxDB2, using influxdb-client Python.

My code:

(local_time_to_unix is an own defined function to convert to Epoch, this function is correct and I've tested other Epoch values as well)


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

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

print(time)

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

Whenever I try to send a datapoint with the .time() function, either nothing happens (no record gets added in InfluxDB) or the timestamp is not correct: the timestamp in influxdb (_start, _stop, _time) is the host time of querying the data. So it constantly changes to the current time of the host. Not the time of adding the datapoint to the DB via Python...

The Python code gets executed successfully without any erros.

I've tried every possible time format, I went through the documentation of InfluxDB and influxdb-client, but nothing works.

.time('1996-02-25T21:20:00.001001231Z') is extracted from the "examples" section from the official documentation. Why doesn't it work for me?

Why doesn't the .time() function work for me on the Point?

Thanks in advance!

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...

1

There are 1 answers

1
fogoo On

I used a window10 computer, Python version 3.10, and then wrote influxdb2(linux system), which is available