gpt4 book ai didi

Python: 'ascii' 编解码器无法解码字节

转载 作者:行者123 更新时间:2023-12-01 02:33:03 26 4
gpt4 key购买 nike

当前代码:

 file.write("\"" + key + "\": " + "\"" + french[key].encode('utf8') + "\"" + ',' + '\n')

字典中的法语键值如下所示:

"YOU_HAVE_COMPLETED_ENROLLMENT": "Vous avez termin\u00e9 l'inscription !"

出现此错误:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 19: ordinal not in range(128)

尝试了这里的所有解决方案,但似乎都不起作用。

最佳答案

你可以使用这个函数对字符串进行unicode

def _parse_value(value):
if type(value) == str:
value = value.decode("utf-8", "ignore").strip()
return value

关于Python: 'ascii' 编解码器无法解码字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46571600/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com