Forums

Problem with parsing a JSON

This code of mine works fine locally and occasionally runs with no errors here, but most of the times it throws an error saying:

Traceback (most recent call last): File "/home/AmirNsr/tweetBot/bot.py", line 266, in <module> makeNews(link) File "/home/AmirNsr/tweetBot/bot.py", line 208, in makeNews for i in data["items"]: KeyError: 'items'

Here is one the JSONs I use as an example, it definitely has the keyword 'items'

And this is the code

def makeNews(link):
r = requests.get(link)
r.text
data = json.loads(r.text)
mojaz=[]
c=0
for i in data["items"]:
    if fel(data["items"][c]["title"]) and notTekrari(data["items"][c]["title"]):
        mojaz.append(c)
        akhbar.append(data["items"][c]["title"])
    c+=1

Thanks for your help in advance

Hi there, when I try and access that JSON url from a console I get the following message:

{"status":"error","message":"Daily rate limit exceeded, please try again later or use an api key."}

try printing out r.text to see if that's what you're seeing as well, and then if so I guess you need to get an api key from them?