Default setup script for Python contains an error

Using a brand new install on Ubuntu, it seems that the new-user-setup/python script contains an error.

The Initialise Client and Write Data steps supply a two part Python script that can be pasted into the terminal using Python3, or run as a script.

During this procedure the following error occurs.

Traceback (most recent call last):
  File "/home/ubuntu/monitor_scripts/", line 13, in <module>
    write_api = client.write_api(write_options=SYNCHRONOUS)
NameError: name 'client' is not defined

The script that is generated by the pages is as follows:

import influxdb_client, os, time
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

token = os.environ.get("INFLUXDB_TOKEN")
org = "My_Data_Org"
url = ""

write_client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)


write_api = client.write_api(write_options=SYNCHRONOUS)
for value in range(5):
  point = (
    .tag("tagname1", "tagvalue1")
    .field("field1", value)
  write_api.write(bucket=bucket, org="QFES_Catalyst", record=point)
  time.sleep(1) # separate points by 1 second

client is not defined at any point. Thus, this line fails:
write_api = client.write_api(write_options=SYNCHRONOUS)

I’m a complete newbie with influx, but it seems like this line:
write_client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)

Should be:
client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)

ie remove the write_ at the start.

1 Like

Hello @anakaine,
Yup you are correct! Thank you for that!
where do you see that error? I’d like to fix the docs.
Also please note if you’re using InfluxDB v3 please use: