Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am getting KeyError

Traceback (most recent call last): File
"C:\Users\user\Desktop\depremleri-goruntuleme-main\main.py", line 15,
in
for item in json["result"]: KeyError: ‘result’

im getting this keyerror error and I don’t know how to solve it can anyone help me urgently (
below is my code)

import json
from os import system
from time import sleep
import requests                                 
from colorama import init, Fore
init(autoreset=True)

while True:

    print(Fore.RED+"            5 1 2 4 - O f f i c a l \n")
    print(Fore.RED+"Tür         "+Fore.CYAN+"Tarih & Saat           "+Fore.GREEN+"Yer           "+Fore.RED+"Büyüklük        "+Fore.YELLOW+"Derinlik")
    print("-------------------------------------------------------------------------------")

    json = requests.post("https://api.orhanaydogdu.com.tr/deprem/live.php").json()
    for item in json["result"]:
        tarih = item["date"]
        yer = item["lokasyon"]
        büyüklük = item["mag"]
        derinlik = item["depth"]

        print(Fore.RED+"Deprem ! "+Fore.CYAN+tarih+Fore.GREEN+" "+yer+Fore.RED+" "+str(büyüklük)+Fore.YELLOW+" "+str(derinlik)) #Depremleri yazdırıyoruz

    sleep(13)
    system("cls")
    sleep(0.6)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

here is your complete code, I just replaced post with get method.

import json
from os import system
from time import sleep
import requests                                 
from colorama import init, Fore
init(autoreset=True)

while True:

    print(Fore.RED+"            5 1 2 4 - O f f i c a l \n")
    print(Fore.RED+"Tür         "+Fore.CYAN+"Tarih & Saat           "+Fore.GREEN+"Yer           "+Fore.RED+"Büyüklük        "+Fore.YELLOW+"Derinlik")
    print("-------------------------------------------------------------------------------")

    json_data = requests.get("https://api.orhanaydogdu.com.tr/deprem/live.php").json()
    for item in json_data ["result"]:
        tarih = item["date"]
        yer = item["lokasyon"]
        büyüklük = item["mag"]
        derinlik = item["depth"]

        print(Fore.RED+"Deprem ! "+Fore.CYAN+tarih+Fore.GREEN+" "+yer+Fore.RED+" "+str(büyüklük)+Fore.YELLOW+" "+str(derinlik)) #Depremleri yazdırıyoruz

    sleep(13)
    system("cls")
    sleep(0.6)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading