I am requesting some data from the weather API and I am trying to save it to a influxdb database.
When I am trying to write the JSON data to the influx database I get a 204 response and no data are written to the database. The exact error from the docker logs is:
[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
My code is:
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)
the json_responce holds the following information:
[{'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}]
I don’t understand why influx refuses to accept the data. Any help is appreciated.