python - UnicodeDecodeError:“ascii”编解码器无法解码位置 223 中的字节 0xc3:序数不在范围内(128)
问题描述
我正在尝试从 k8s 中容器内的命令行为 django 应用程序执行读取文件命令,但出现此错误。我可以在本地执行相同的命令,但不能在 k8s 内部执行。我的完整错误堆栈如下:
raceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/code/setup/management/commands/load.py", line 40, in handle
raw = file.read()
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 223: ordinal not in range(128)
这是代码:
with codecs.open(filename, 'r', encoding='utf-8') as file:
raw = file.read()
data = json.loads(raw)
解决方案
推荐阅读
- javascript - 在将嵌套锚标记添加到部分元素后单击事件适得其反
- python - 熊猫通过数据框的 2 列将一个系列映射到另一个系列
- pandas - Pandas - 将日期转换为日期时间格式
- java - 导航抽屉未使用 RecyclerView 加载布局
- java - 如何将列表列表转换为 Java 8 中的列表?没有流,只有 for( 或 foreach) 和 if
- asp.net-mvc - 返回递归结果
- oracle - 错误(11,10):PLS-00306:调用“CONSTRUCT”时参数的数量或类型错误
- excel - 通过引用 Cells.Find() 有条件 - VBA
- java - java.lang.UnsupportedClassVersionError - 在 MAC OSX 上 - 不支持的类文件主要版本 56
- python - 无效的语法 (
,第 89 行)-pylint(语法错误)