0

Python Version - 2.7 InfluxDB Version - 1.5.0

I'm a newbie, and I am trying to connect my InfluxDB database with Python so I can write code for future projects.

I tested out the example program from this link. (Direct code below)

from influxdb import InfluxDBClient

json_body = [
{
    "measurement": "cpu_load_short",
    "tags": {
        "host": "server01",
        "region": "us-west"
    },
    "time": "2009-11-10T23:00:00Z",
    "fields": {
        "value": 0.64
    }
  }
]

client = InfluxDBClient('localhost', 8086, 'root', 'root', 'example')

client.create_database('example')

client.write_points(json_body)

result = client.query('select value from cpu_load_short;')

print("Result: {0}".format(result))

Upon running the program, I am receiving this error.

Traceback (most recent call last):
  File "influxentryexample.py", line 19, in <module>
    client.create_database('example')
  File "/usr/lib/python2.7/dist-packages/influxdb/client.py", line 318, in create_database
    status_code=201
  File "/usr/lib/python2.7/dist-packages/influxdb/client.py", line 124, in request
    raise InfluxDBClientError(response.content, response.status_code)
influxdb.client.InfluxDBClientError: 404: 404 page not found
1

1 Answer 1

2

if you install influxdb without changing its config file, you could login without using username and password, so just type:

client = influxdb.InfluxDBClient(host='localhost', port=8086)

and then you will establish the connection between python and influxdb
but in this way, you did not assign which database you want to insert data before write_points(jsonbody). You need to use client.create_database() and client.switch_database() like:

client.create_database('example')
client.switch_database('example')

But as the learner (so was I) you'd better learn how to use restful API request to do some work.It will help us to understand how influxdb works

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.