Skip to content Skip to sidebar Skip to footer

Keyerror In Console, But Key Exists And Function Works Fine

I have looked at all the other keyerror questions on here, but I couldn't find one that addressed my situation. I am pulling location information from Google and reading the json i

Solution 1:

Actually "price_level" is outside of the list.

You'll have it with geocode_result['price_level']

Solution 2:

keys in json file have to be double quoted - in my honest opinion.

"In JSON, keys must be strings, written with double quotes" from here : https://www.w3schools.com/js/js_json_syntax.asp

Solution 3:

As a few people have pointed out, directly and indirectly, I should start a new ticket for the issue that I am facing. The issue is that the value that I was calling 'price_level' is not a key in 'geocode_result'. Some how I was still able to get the values from calling it, but the keyerror was triggered post-output. Now I have to figure out how to turn 'price_level' into a key.

Thank you all for your help in figuring this out.

Turns out the issue was that not all of the responses being fed back contained all the key's that I was calling. That is why it would run for what seemed like the entire script, and then stop when the keyerror was raised towards the end. I'm going to add a try statement to the for loop section.

Post a Comment for "Keyerror In Console, But Key Exists And Function Works Fine"