Click here to Skip to main content
15,667,536 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Consider the code below:
emaUrl = ""

symbolEma21Req = requests.get(emaUrl, {
symbolEma21Res = symbolEma21Req.json()

symbolEma8Req = requests.get(emaUrl, {
symbolEma8Res = symbolEma8Req.json()

Both of the requests above, return a `dict` which contains `value`. So I check them with operators:
if symbolEma8Res['value'] < symbolEma21Res['value']:
        print('EMA 8 Under EMA 21')

Previously I used this and it was fine. But from yesterday I get this error:
KeyError: 'value'

And why this happens? I appreciate that.

What I have tried:

I've tried the exact code before.
Updated 24-May-22 23:47pm

Probably because the response you're receiving has changed. Either the structure of the JSON returned has changed, or your credentials no longer work.

We can't tell you which because we don't have access to that site. You need to debug your code to inspect the response, and then work out why it's not returning what you're expecting. Nobody here can do that for you.
Share this answer
Ali Bahaari 2021 28-Jul-21 13:31pm    
I've checked it. Nothing has been changed. When I print the JSON, it shows me this: {'value': 1.24}
exception KeyError
Raised when a mapping (dictionary) key is not found in the set of existing keys.
Share this answer
Ali Bahaari 2021 28-Jul-21 13:31pm    
It's existed.
Richard MacCutchan 29-Jul-21 3:57am    
The error message clearly tells you that it does not.
Ali Bahaari 2021 29-Jul-21 6:40am    
Yes, it was my fault. Thank you.
As Richard said, the structure of the JSON has been changed.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900