[Solved] Key error u’True when checking for a value in JSON dump stored in python dictionary


The first rule of debugging is to assume that the error message is telling you the truth. In this case it is telling you keyerror u'True.

This means that somewhere in your code you’re doing the equivalent of some_dictionary[u'True']. In the code you posted, there is nothing that is using the literal value True as a key, so it must be in a variable. Since you didn’t post the actual error, I have to guess which line is causing the error.

Most likely, the error is coming from this code: user_info['response'][field_value]). That means that field_value is likely u'True'. The question now becomes, why is it true? Since your code doesn’t show where that value comes from, there’s no way I can answer that. You’ll have to do some additional debugging where you set that variable.

Looking at the name of the variable, it appears you’re expecting the variable to contain a value, but you’re using it as a key. Perhaps that is the problem? Maybe that line of code should be user_info['response'][user_name] (ie: replace key_value with user_name)?

solved Key error u’True when checking for a value in JSON dump stored in python dictionary