[JSON数据格式写入InfluxDB错误,结果返回204响应

问题描述 投票:0回答:1

我正在从天气API请求一些数据,并且我试图将其保存到influxdb数据库中。

[当我尝试将json数据写入Influx数据库时,收到204响应,并且没有数据写入数据库。码头工人日志中的确切错误是:

[httpd] 172.17.0.1 - root [17/Jun/2020:23:00:35 +0000] "POST /write?db=external_weather HTTP/1.1" 204 0 "-" "python-requests/2.23.0" 5ac727b3-b0ee-11ea-8152-0242ac110002 169

我的代码是:

import requests
from requests.exceptions import HTTPError
from influxdb import InfluxDBClient

url = "http://api.openweathermap.org/data/2.5/weather"
payload = {
    "lat": 51.509865,
    "lon": -0.118092,
    # "exclude": {"minute", "hourly", "daily"},
    "appid": "xxx",
    "units": "metric"}


try:  

    responce = requests.get(url, params=payload)
    responce.raise_for_status()
    json_responce = [responce.json()]
    print(responce.status_code)


except HTTPError as http_err:
    print(f'HTTP error occurred: {http_err}')

except Exception as err:
    print(f'Other error occurred: {err}')


# Send to InfluxDB


'''
'''
client = InfluxDBClient()
client.write_points(json_responce, database='external_weather')
print(json_responce)

json_responce包含以下信息:

[{'coord': {'lon': -0.12, 'lat': 51.51}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10n'}], 'base': 'stations', 'main': {'temp': 16.14, 'feels_like': 15.39, 'temp_min': 15.56, 'temp_max': 16.67, 'pressure': 1012, 'humidity': 71}, 'wind': {'speed': 1.49, 'deg': 143}, 'rain': {'1h': 0.9}, 'clouds': {'all': 100}, 'dt': 1592435463, 'sys': {'type': 3, 'id': 268730, 'country': 'GB', 'sunrise': 1592451762, 'sunset': 1592511641}, 'timezone': 3600, 'id': 2643743, 'name': 'London', 'cod': 200}]

我不明白为什么Influx拒绝接受数据。

python influxdb
1个回答
0
投票

[根据InfluxDBClient的文档,实际上将数据写入流入DB时需要204响应代码,请参阅https://influxdb-python.readthedocs.io/en/latest/api-documentation.html#influxdb.InfluxDBClient.write

请仔细检查在您的情况下将数据写入涌入是否确实存在问题。

© www.soinside.com 2019 - 2024. All rights reserved.