Skip to content Skip to sidebar Skip to footer

'ascii' Codec Can't Decode Byte 0xc3 In Position 3

Not sure why this error is coming up because of a special character in the value, I'm trying to get the value of a key from the json using this recursive function provided by @Brie

Solution 1:

There's a couple of things wrong about your code:

  1. When you call on an item from JSON you should assign to variable then encode or encode as it's being loaded.
  2. When you encode a string, which is what json.load type is, you're changing it to byte. Adding str + byte after you properly encode the variable will rise another error.

Try the following:

j = json.load(data_file, encoding='utf-8')
#....path = path + element + ' = ' + str(JSON[element])

Solution 2:

Usually such errors occur when somebody tries to encode a string that was not decoded. I would suggest JSON[element].decode('utf-8'). You can encode it later if you need to.

Post a Comment for "'ascii' Codec Can't Decode Byte 0xc3 In Position 3"