2016-04-25 483 views
6

我想使用influxdb-python庫,我發現here。但我甚至不能讓教程程序工作。influxdb python:404頁面未找到

當我運行下面的示例代碼:

$ python 

>>> 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.create_database('example') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    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 

我安裝的版本:

[email protected]:~ $ influx 
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring. 
Connected to http://localhost:8086 version 0.9.6.1 
InfluxDB shell 0.9.6.1 

這將是真的很好,如果有人能指出我在這裏的問題。

UPDATE

也許這是有幫助的。我在樹莓派3傑西,並用此tuturial link

更新2

安裝influxdb如果我跑curl http://localhost:8086我還獲得404找不到網頁。在端口8083我得到了迴應。

回答

1

我已經在樹莓PI2運行Influxdb。

InfluxDB shell 0.12.1是我有的版本。您正在運行可能已過時的0.9.6.1,但仍然是您使用的回購中可用的最新版本。

你的端口似乎正確,快速的netstat顯示的是:

tcp6  0  0 :::8083     :::*     LISTEN  17740/influxd 
tcp6  0  0 :::8086     :::*     LISTEN  17740/influxd 
tcp6  0  0 :::8088     :::*     LISTEN  17740/influxd 

爲了測試它,我用同樣的示例腳本像你一樣,有輕微的變化:

#!/usr/bin/python 

import random 
from datetime import datetime 

from influxdb import InfluxDBClient 


query = 'select value from wetter;' 
client = InfluxDBClient(host='127.0.0.1', database='wetter') 
print(client) 

current_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') 
json_body = [ 
    { 
     "measurement": "temperature", 
     "tags": { 
      "host": "192.168.0.82", 
      "location": "room" 
     }, 
     "time": current_time, 
     "fields": { 
      "value": random.random() 
     } 
    } 
] 
print(json_body) 

client.write_points(json_body) 

我再啓動while true; do ./influxdb-test.py; sleep 2; done這個腳本會每2秒插入一個新條目。

> select * from temperature 

1462865736000000000 192.168.0.82 room 0.116745414817 
1462866059000000000 192.168.0.82 room 0.576278097718 
1462866062000000000 192.168.0.82 room 0.731955354635 
1462866065000000000 192.168.0.82 room 0.536106447983 
1462866068000000000 192.168.0.82 room 0.965246396917 
1462866070000000000 192.168.0.82 room 0.785592521739 
3

我無法發表評論,因爲我沒有聲望。

我發現與樹莓派和v0.12.2相同的問題。如果你去https://docs.influxdata.com/influxdb/v0.12/guides/writing_data/有這個命令

捲曲-G http://localhost:8086/query --data-進行urlencode 「Q = CREATE DATABASE MYDB」

它爲我工作。

更新1

我不認爲你已經正確安裝了Python InfluxDB驅動程序。按照InfluxDB-Python頁面上的步驟操作。特別要確保以sudo運行以下命令。

PIP安裝influxdb

PIP安裝--upgrade influxdb

+0

謝謝你,我已經使用這個方法,但我正在尋找我的問題與influxdb的Python的lib – IIIIIIIIIIIIIIIIIIIIII

+0

測試的教程,下載0.12.2的tar.gz(HTTPS答案:// DL。 influxdata.com/influxdb/releases/influxdb-0.12.2-1_linux_armhf.tar.gz)在64位Linux VM上工作,但不在樹莓派上工作。 – sdbol

+0

通過[InfluxDB CLI](https://docs.influxdata.com/influxdb/v0.12/tools/shell)與Rasune Pi上的InfluxDB交互也有類似的問題嗎?我想知道這是一個通用的ARM InfluxDB問題還是特定的Python客戶端。 –