Skip to content
Advertisement

KeyError: ‘variant’ while getting data from API , even tho variant data exists on API

[Here is the API snippet. I am working on]

1

Here is the code snippet that fetching API snippet above.

JavaScript

If I remove i[“variant”] everything works perfectly but i[“variant”] is throwing key error even tho “variant”: “Shaper/Redeemer” exists on the JSON file. Thanks for any help.

Error code:

JavaScript

Advertisement

Answer

You’re showing us a screenshot where the first line has a variant, but your code will fail unless every line has a variant.

What is the output of this snippet?

JavaScript

If it outputs any lines, there’s your problem. If it doesn’t, something deeper is going on. I would try to catch the KeyError exception and put a breakpoint in the handler to continue investigating.

Advertisement