<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Influxdb, python csv export, unauthorized]]></title><description><![CDATA[<p dir="auto">Hallo zusammen,<br />
nutze bei meinem Smarthome System (KNX, IOBroker, InfluxDB, Grafana) die influxdb in einem docker-container zum data-logging. Nun möchte ich die Daten zum weiter exportieren in ein .csv-file haben. ChatGPT leistet da auch gute Dienste für ein Script:</p>
<pre><code># manuell ausführen mit
# /bin/python3 /volume1/Christof/Daten/Organisation/030_Infrastruktur/020_Devices/Smart-Home/Logging/csv-export/export_influxdb_to_csv.py

from influxdb import InfluxDBClient
import csv

# InfluxDB connection details
host = 'localhost'
port = 8086
database = 'logging1'
user = 'iobroker'
password = 'meinpasswort'

# Output CSV file
csv_file_path = '/volume1/Christof/Daten/Organisation/030_Infrastruktur/020_Devices/Smart-Home/Logging/influx_output.csv'

# Query to select all data from all measurements
query = 'SELECT * FROM /.*/'

# Connect to InfluxDB
client = InfluxDBClient(host, port, user, password, database)

# Get the query result
result = client.query(query)

# Extract data points from the result
data_points = [point for series in result for point in series]

# Write data to CSV file
with open(csv_file_path, 'w', newline='') as csv_file:
    csv_writer = csv.writer(csv_file)

    # Write header
    csv_writer.writerow(data_points[0].keys())

    # Write data
    for point in data_points:
        csv_writer.writerow(point.values())

print(f'Data exported to {csv_file_path}')
</code></pre>
<p dir="auto">Allerdings bekomme ich:</p>
<pre><code> File "/usr/lib/python3.8/site-packages/influxdb/client.py", line 378, in request
    raise InfluxDBClientError(err_msg, response.status_code)
influxdb.exceptions.InfluxDBClientError: 401: {"code":"unauthorized","message":"Unauthorized"}
</code></pre>
<p dir="auto">User/Passwort müssten passen, allerdings bin ich mir beim Namen der Datenbank nicht ganz sicher, ist das der Bucketname oder wo finde ich den?</p>
<p dir="auto">Oder was könnte noch Ursache für Fehler sein?</p>
<p dir="auto">Vielen DAnk im voraus.</p>
]]></description><link>https://forum.iobroker.net/topic/70591/influxdb-python-csv-export-unauthorized</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 17:58:49 GMT</lastBuildDate><atom:link href="https://forum.iobroker.net/topic/70591.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 27 Nov 2023 21:06:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Influxdb, python csv export, unauthorized on Fri, 01 Dec 2023 23:52:53 GMT]]></title><description><![CDATA[<p dir="auto">@dp20eic stimmt, ChatGPT ist einfach schneller als doku lesen (rtfm ist oldschool im zeitalter von KI), heute geht man auch nicht mehr in die Bibliothek, sondern fragt das Internet, ebenso kann man ChatGPt alles auf einmal machen lassen:</p>
<ul>
<li>doku für mich lesen</li>
<li>das relevante davon extrahieren</li>
<li>und gleich für meinen use-case anwenden und das script schreiben.</li>
</ul>
<p dir="auto">... nach ein paar weiteren Iterationen wars dann auch schon perfekt:</p>
<pre><code># manuell ausführen mit
# /bin/python3 /volume1/Christof/Daten/Organisation/030_Infrastruktur/020_Devices/Smart-Home/Logging/csv-export/export_influxdb_to_csv_tmp-ist-wohn_6.py


from influxdb_client import InfluxDBClient, Point, WriteOptions
import pandas as pd
import csv
import warnings
from influxdb_client.client.warnings import MissingPivotFunction
from pathlib import Path

# InfluxDB credentials
url = "http://10.ab.xy.rs:8086/"
token = "Rea..."
myorg = "smarthome"
mybucket = "logging1"

# Output file path
output_file_path = "/volume1/Christof/Daten/Organisation/030_Infrastruktur/020_Devices/Smart-Home/Logging/influx_output_tmp-ist-wohn_2.csv"

# Create InfluxDB client
client = InfluxDBClient(url=url, token=token)

# Suppress the warning about the missing pivot function
warnings.simplefilter("ignore", MissingPivotFunction)

# Check connection
try:
    health = client.health()
    if health.message == 'ready for queries and writes':
        print("Connection successful.")

        # Specify your InfluxDB query here
        query = 'from(bucket: "logging1") |&gt; range(start: -1d)'

        # Run the query
        tables = client.query_api().query(org=myorg, query=query)
        
        # Specify the values you want to filter for
        filter_measurement = "knx.0.Heizung__Klima__Lüftung.EG.Heiz-Wohn-Ess_Temp-IST"
        filter_field = "value"

        # Extract and export data to CSV
        with open(output_file_path, 'w', newline='') as csvfile:
            csv_writer = csv.writer(csvfile)

            # Write header
            csv_writer.writerow(["_time", "_value", "_field", "_measurement"])

            # Print all measurement names for debugging
            measurement_names = set()
            for table in tables:
                for record in table.records:
                    measurement_names.add(record.get_measurement())
            print(f"All measurement names: {measurement_names}")

            # Write data with filters
            for table in tables:
                for record in table.records:
                    # Check if both conditions are met
                    if record.get_measurement() == filter_measurement and record.get_field() == filter_field:
                        csv_writer.writerow([record.get_time(), record.get_value(), record.get_field(), record.get_measurement()])
                
            print(f"Data exported to {output_file_path}")
    else:
        print(f"Connection failed. InfluxDB status: {health.message}")
except Exception as e:
    print(f"An error occurred: {e}")
</code></pre>
<p dir="auto">KI ist echt ein Gamechanger.... :)</p>
]]></description><link>https://forum.iobroker.net/post/1089256</link><guid isPermaLink="true">https://forum.iobroker.net/post/1089256</guid><dc:creator><![CDATA[Chrisham]]></dc:creator><pubDate>Fri, 01 Dec 2023 23:52:53 GMT</pubDate></item><item><title><![CDATA[Reply to Influxdb, python csv export, unauthorized on Tue, 28 Nov 2023 05:23:48 GMT]]></title><description><![CDATA[<p dir="auto">@dp20eic sagte in <a href="/post/1087511">Influxdb, python csv export, unauthorized</a>:</p>
<blockquote>
<p dir="auto">P.S.: <a class="plugin-mentions-user plugin-mentions-a" href="/user/marc-berg" aria-label="Profile: Marc-Berg">@<bdi>Marc-Berg</bdi></a> moin, Du tippst schneller als ich :)</p>
</blockquote>
<p dir="auto">Ne, ich schreibe weniger!  :-)</p>
]]></description><link>https://forum.iobroker.net/post/1087513</link><guid isPermaLink="true">https://forum.iobroker.net/post/1087513</guid><dc:creator><![CDATA[Marc Berg]]></dc:creator><pubDate>Tue, 28 Nov 2023 05:23:48 GMT</pubDate></item><item><title><![CDATA[Reply to Influxdb, python csv export, unauthorized on Tue, 28 Nov 2023 05:18:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisham" aria-label="Profile: chrisham">@<bdi>chrisham</bdi></a> sagte in <a href="/post/1087471">Influxdb, python csv export, unauthorized</a>:</p>
<blockquote>
<p dir="auto">Oder was könnte noch Ursache für Fehler sein?</p>
</blockquote>
<p dir="auto">Moin,</p>
<p dir="auto">Dokumentation nicht gelesen ;)<br />
Die Hersteller geben sich da echt Mühe und viel Geld aus :)</p>
<p dir="auto">Da Du ja von Bucket sprichst, gehe ich davon aus, das Du <code>influxDB &gt;V2</code> nutzt, dann ist das nicht <code>user</code>, <code>password</code>, sondern <strong><code>org</code></strong> und <strong><code>token</code></strong>!<br />
Und ja, ein Bucket ist die Datenbank im <code>influxDB V2</code> Sprachgebrauch.</p>
<p dir="auto">VG<br />
Bernd</p>
<p dir="auto">P.S.: <a class="plugin-mentions-user plugin-mentions-a" href="/user/marc-berg" aria-label="Profile: Marc-Berg">@<bdi>Marc-Berg</bdi></a> moin, Du tippst schneller als ich :)</p>
]]></description><link>https://forum.iobroker.net/post/1087511</link><guid isPermaLink="true">https://forum.iobroker.net/post/1087511</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 28 Nov 2023 05:18:18 GMT</pubDate></item><item><title><![CDATA[Reply to Influxdb, python csv export, unauthorized on Tue, 28 Nov 2023 05:10:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisham" aria-label="Profile: chrisham">@<bdi>chrisham</bdi></a><br />
ChatGPT hat dir leider verschwiegen, dass es Unterschiede bei den Anmeldeparametern zwischen InfluxDB 1.x und 2.x gibt.</p>
]]></description><link>https://forum.iobroker.net/post/1087510</link><guid isPermaLink="true">https://forum.iobroker.net/post/1087510</guid><dc:creator><![CDATA[Marc Berg]]></dc:creator><pubDate>Tue, 28 Nov 2023 05:10:32 GMT</pubDate></item></channel></rss>