Python KeyError When Trying To Access Dictionary Index 0: Dict[0]
Edit: I've moved this question to a new post: Python: KeyError when Calling Valid Key/Index in Dict I'm successfully receiving some properly formatted JSON data via websocket: whil
Solution 1:
The problem in while True: on first iteration you got a result 15800.0, but on second iteration your dictionary do not contains key = 'price'
Create a guard in while True loop, like in for loop:
while True:
result = ws.recv()
result = json.loads(result)
if result and 'price' in result:
print(result['price'])
...
Thanks to sKwa, answered here: Python: KeyError when Calling Valid Key/Index in Dict
Post a Comment for "Python KeyError When Trying To Access Dictionary Index 0: Dict[0]"