繁体   English   中英

Python - 如何在 Heroku 上使用 JSON 解决 UTF8 问题?

[英]Python - How do i solve UTF8 issues with JSON on Heroku?

我有一个 .txt 填充了字典列表,其中有一些文件名,一些包含 ä ö ü。 我试图用这个代码加载它:

with open('res/mp3s_stats.txt', 'r', encoding="utf-8") as f:
     data = json.load(f)

但我收到此错误:

  File "C:\Users\laure\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\laure\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 855, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\laure\AppData\Roaming\Python\Python38\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 6184: invalid continuation byte

我能做些什么来解决这个问题? 每次写入或读取此文件时,我都已使用 encoding="utf-8" :/

我的直觉是你的 txt 文件实际上不是 UTF-8 编码的。 0XE4是有效的 ISO-8859-15 字符 (ä),但不是有效的 UTF-8 字符。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM