如何修复“UnicodeDecodeError:'cp949'编解码器无法解码位置 24 中的字节 0xeb:非法多字节序列”

2024-01-03

我只是用 python3 制作不和谐机器人

@client.event
async def on_message(message):
    #if bot ignore
    if message.author.bot:
        return None
    
    if message.content.startswith('!meal'):
        with open('menu.json') as json_file:
            data = json.load(json_file)
        channel = message.channel
        await channel.send('This is meal info!')
        await channel.send(data())

但我得到了

UnicodeDecodeError: 'cp949' codec can't decode byte 0xeb in position 24: illegal multibyte sequence

这个错误..我怎样才能自动打开这个json文件?


打开 JSON 时可能需要指定编码,如下所示:

with open('menu.json', encoding='utf-8') as json_file:

你替换的地方utf-8使用您保存的任何编码menu.json with.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何修复“UnicodeDecodeError:'cp949'编解码器无法解码位置 24 中的字节 0xeb:非法多字节序列” 的相关文章

随机推荐