json.dump - UnicodeDecodeError: 'utf8' codec can't decode byte 0xbf in position 0: invalid start byte

后端 未结 1 1902
轮回少年
轮回少年 2020-12-29 10:22

I have a dictionary data where I have stored:

  • key - ID of an event

  • value - the name of this event, w

相关标签:
1条回答
  • 2020-12-29 11:06

    The exception is caused by the contents of your data dictionary, at least one of the keys or values is not UTF-8 encoded.

    You'll have to replace this value; either by substituting a value that is UTF-8 encoded, or by decoding it to a unicode object by decoding just that value with whatever encoding is the correct encoding for that value:

    data['142'] = data['142'].decode('latin-1')
    

    to decode that string as a Latin-1-encoded value instead.

    0 讨论(0)
提交回复
热议问题