Wo liegst in diesm Code das Problem?
        api_key = "geeeeeeeeeeändert"
        id = "2959047"
        complete_url = ("http://api.openweathermap.org/data/2.5/forecast?id=" + id + "&appid=" + api_key)
        response = requests.get(complete_url)
        
        WeatherData = response.json()
        print("Luftfeuchtigkeit: {}%".format(WeatherData["main"]["humidity"]))
        print("Luftdruck: {} hpa".format(WeatherData["main"]["pressure"]))
        print("Temperatur: {}° C".format(str(WeatherData["main"]["temp"] - 273)))
        print("Max. Temperatur: {}° C".format(str(WeatherData["main"]["temp_max"] - 273)))
        print("Min. Temperatur: {}° C".format(str(WeatherData["main"]["temp_min"] - 273)))
        print("Windgeschwindigkeit: {} m/s".format(WeatherData["wind"]["speed"]))
        print("Windrichtung: {}°".format(WeatherData["wind"]["deg"]))

Oben ist Ein Auszug aus dem Code welcher Probleme bereitet.

Satisfactory&Anderes Bot#1309 hat sich erfolreich mit dem server verbunden
Ignoring exception in on_message
Traceback (most recent call last):
 File "C:\Users\Mein Name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 343, in _run_event
   await coro(*args, **kwargs)
 File "c:\Users\Mein Name\Desktop\bot.py", line 58, in on_message
   print("Luftfeuchtigkeit: {}%".format(WeatherData["main"]["humidity"]))
KeyError: 'main'

Open Weather Map gibt mir bei einem manuellen Api Abruf per Browser Folgende Antwort: (zu lang für gute frage, habe mal den Code sammt einem Api response von heute Mittag auf eine Cloud hochgeladen.)

https://shared-assets.adobe.com/link/e9b57595-6572-4629-4efa-154577b4ef46

Vielen Dank

Computer, Code, Python, JSON

Meistgelesene Beiträge zum Thema Computer