【问题标题】:influxdb python: 404 page not foundinfluxdb python:找不到404页面
【发布时间】:2016-04-25 17:14:17
【问题描述】:

我正在尝试使用我发现 here 的 influxdb-python 库。但我什至无法让教程程序正常工作。

当我运行以下示例代码时:

$ 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

我安装的版本:

pi@raspberrypi:~ $ 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

如果有人能在这里指出我的问题,那就太好了。

更新

也许这会有所帮助。我和 Jessie 一起在 Raspberry Pi 3 上,并用这个教程安装了 influxdb link

更新 2

如果我运行curl http://localhost:8086,我也会得到 404 页面未找到。在端口 8083 上,我得到了响应。

【问题讨论】:

    标签: python influxdb


    【解决方案1】:

    我无法发表评论,因为我没有声誉。

    我在树莓派 PI 和 v0.12.2 中发现了同样的问题。如果你去https://docs.influxdata.com/influxdb/v0.12/guides/writing_data/有这个命令

    curl -G http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb"

    它对我有用。

    更新 1

    我认为您没有正确安装 Python InfluxDB 驱动程序。按照InfluxDB-Python 页面上的步骤操作。具体请确保以 sudo 身份运行以下命令。

    pip install influxdb

    pip install --upgrade influxdb

    【讨论】:

    • 谢谢,我已经使用了这个解决方法,但我正在为我的 influxdb-python 库问题寻找答案
    • 使用下载 0.12.2 tar.gz (dl.influxdata.com/influxdb/releases/…) 测试教程在 64 位 Linux VM 上运行,但在树莓派 PI 上运行不正常。
    • 通过InfluxDB CLI 在 Rasberry Pi 上与 InfluxDB 交互是否也有类似问题?我想知道这是一般 ARM InfluxDB 问题还是特定于 python 客户端。
    • 我没有尝试过 InfluxDB CLI。我很确定 Python 驱动程序是最新的,因为我在 AWS 上使用 64 位 Linux 虚拟机进行了尝试。根据Influx documentation,它说日志文件位于/var/log/influxdb/。 @MarkB,你能看看日志看看它们显示了什么吗?
    • 感谢 UPDATE 1 解决了我在 RPi3 上的问题!
    【解决方案2】:

    我在 Raspberry 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
    

    【讨论】:

      猜你喜欢
      • 2016-03-31
      • 2013-06-28
      • 1970-01-01
      • 2016-08-01
      • 2016-08-01
      • 2015-10-22
      • 2014-03-20
      • 2020-10-27
      • 2019-07-21
      相关资源
      最近更新 更多